Add colors, fix bugs

This commit is contained in:
2019-10-18 22:09:25 +02:00
parent b23bfb9ff5
commit 5286c94dca
8 changed files with 132 additions and 8 deletions

View File

@@ -20,8 +20,8 @@ public interface TransactionRepository extends CrudRepository<Transaction, Long>
@Query("SELECT SUM(t.amount) FROM Transaction t JOIN t.periods p JOIN t.toAccount a WHERE a.type IN :expenseTypes AND p = :period")
Long getExpensesForPeriod(Period period, AccountType... expenseTypes);
@Query("SELECT SUM(t.amount) FROM Transaction t JOIN t.periods p JOIN t.toAccount a WHERE a.type IN :expenseTypes GROUP BY p ORDER BY p.start ASC")
List<Long> getExpensesForAllPeriods(AccountType... expenseTypes);
@Query("SELECT SUM(t.amount) FROM Transaction t JOIN t.periods p JOIN t.toAccount a JOIN t.fromAccount f WHERE a.type IN :expenseTypes AND f.type != :startType GROUP BY p ORDER BY p.start ASC")
List<Long> getExpensesForAllPeriods(AccountType startType, AccountType... expenseTypes);
// The HQL contains a hack because Hibernate can't resolve the alias of the CASE column in the GROUP BY clause
// That's why the generated alias is used directly in the HQL. It will break if the columns in the SELECT clause get reordered

View File

@@ -235,6 +235,13 @@ public class TransactionService {
return response;
}
/**
* This method calculates the expenses done in the current period; this is the sum of
* all bookings to {@link AccountType#EXPENSE EXPENSE} or {@link AccountType#LIABILITY LIABILITY}
* accounts.
*
* @return the sum of expenses - may be <code>0</code>
*/
public Long getExpensesCurrentPeriod() {
final Period expensePeriod = this.periodService.getCurrentExpensePeriod();
@@ -244,10 +251,25 @@ public class TransactionService {
return Optional.ofNullable(expensesCurrentPeriod).orElse(Long.valueOf(0l));
}
/**
* This method gets all sums of expenses of all periods, ordered from oldest to newest.
*
* @return the sums of expenses - may be empty
* @see TransactionService#getExpensesCurrentPeriod()
*/
public List<Long> getExpensesAllPeriods() {
return this.transactionRepository.getExpensesForAllPeriods(AccountType.EXPENSE, AccountType.LIABILITY);
return this.transactionRepository.getExpensesForAllPeriods(AccountType.START, AccountType.EXPENSE, AccountType.LIABILITY);
}
/**
* This method gets the total values of all expense periods of the given year; that is
* the sum of all bookings for {@link AccountType#EXPENSE EXPENSE},
* {@link AccountType#LIABILITY LIABILITY} and {@link AccountType#INCOME INCOME} accounts
* grouped by the account type and period.
*
* @param year the year to get the expense period totals for
* @return the expense period totals for the given year
*/
public Iterable<ExpensePeriodTotal> getExpensePeriodTotals(Integer year) {
final Iterable<Period> periods = this.periodService.getAllExpensePeriodsForYear(year);