Add end balance to account statistic

This commit is contained in:
2020-03-16 20:35:56 +01:00
parent eee891a534
commit 442f2d6087
7 changed files with 51 additions and 15 deletions

View File

@@ -21,6 +21,7 @@ public class AccountStatistic {
private long transactionCountFrom;
private long spendingTotalTo;
private long transactionCountTo;
private long endBalance;
public Long getId() {
return id;
@@ -73,4 +74,12 @@ public class AccountStatistic {
public void setTransactionCountTo(long transactionCountTo) {
this.transactionCountTo = transactionCountTo;
}
public long getEndBalance() {
return endBalance;
}
public void setEndBalance(long endBalance) {
this.endBalance = endBalance;
}
}

View File

@@ -17,7 +17,7 @@
<properties>
<packaging.type>jar</packaging.type>
<activeProfiles>postgres,dev</activeProfiles>
<activeProfiles>hsqldb,dev</activeProfiles>
<deploymentProfile>mk</deploymentProfile>
</properties>

View File

@@ -16,4 +16,7 @@ public interface AccountStatisticRepository extends CrudRepository<AccountStatis
@Query("SELECT a FROM Account a WHERE a NOT IN (SELECT accStat.account FROM AccountStatistic accStat WHERE accStat.period = :period) AND a.status = :accountStatus")
Iterable<Account> getAccountsWithoutStatisticInPeriod(Period period, AccountStatus accountStatus);
@Query("SELECT accStat FROM AccountStatistic accStat WHERE accStat.period = :period")
Iterable<AccountStatistic> getAllForPeriod(Period period);
}

View File

@@ -63,8 +63,8 @@ public class AccountStatisticService {
}
/**
* This method creates an {@link AccountStatistic}s entry with from and to spending <code>0</code>,
* for every account not used in a booking in the given period.
* This method creates an {@link AccountStatistic}s entry with from and to spending <code>0</code>, for every
* account not used in a booking in the given period.
*
* @param period to generate the null statistic entries for
*/
@@ -74,20 +74,20 @@ public class AccountStatisticService {
.getAccountsWithoutStatisticInPeriod(period, AccountStatus.OPEN);
this.accountStatisticRepository.saveAll(IterableUtils.toList(accountsWithoutStat)
.stream()
.map(a -> {
final AccountStatistic as = new AccountStatistic();
.stream()
.map(a -> {
final AccountStatistic as = new AccountStatistic();
as.setTransactionCountTo(0);
as.setSpendingTotalTo(0);
as.setTransactionCountFrom(0);
as.setSpendingTotalFrom(0);
as.setAccount(a);
as.setPeriod(period);
as.setTransactionCountTo(0);
as.setSpendingTotalTo(0);
as.setTransactionCountFrom(0);
as.setSpendingTotalFrom(0);
as.setAccount(a);
as.setPeriod(period);
return as;
})
.collect(Collectors.toList()));
return as;
})
.collect(Collectors.toList()));
}
private AccountStatistic calculateInternal(Account account, Period period, long amount, boolean from, int multiplier) {
@@ -111,4 +111,19 @@ public class AccountStatisticService {
return accountStatistic;
}
@Transactional(propagation = Propagation.REQUIRED)
public void takeOverEndBalances(Period period) {
final Iterable<AccountStatistic> allForPeriod = this.accountStatisticRepository.getAllForPeriod(period);
this.accountStatisticRepository.saveAll(IterableUtils.toList(allForPeriod)
.stream()
.map(as -> {
as.setEndBalance(as.getAccount().getCurrentBalance());
return as;
}
)
.collect(Collectors.toList())
);
}
}

View File

@@ -66,6 +66,8 @@ public class PeriodService {
this.accountStatisticService.generateNullStatisticsForUnusedAccounts(currentPeriod);
this.accountStatisticService.takeOverEndBalances(currentPeriod);
response = ResponseReason.OK;
} catch (Exception e) {
LOGGER.error("Could not close current expense period!", e);
@@ -90,6 +92,8 @@ public class PeriodService {
this.periodRepository.save(expenseYearPeriod);
this.periodRepository.save(nextExpenseYearPeriod);
this.accountStatisticService.takeOverEndBalances(expenseYearPeriod);
}
}

View File

@@ -0,0 +1,2 @@
ALTER TABLE account_statistic
ADD COLUMN end_balance BIGINT;

View File

@@ -1,3 +1,6 @@
v27 -> v28:
- Add account end balance to account statistics for closed expense periods. This is currently not visible in the UI
v26 -> v27:
- Changed sort order of accounts in overview page. The accounts are now sorted by the account type first (BCILES), then
by the account group name and then by the account ID, leading to an overall more organic order of accounts