Expenses on budget per month

This commit is contained in:
2019-11-09 13:36:27 +01:00
parent 0d3da83879
commit aed32a4a28
2 changed files with 9 additions and 4 deletions
@@ -19,10 +19,15 @@ public interface CategoryRepository extends PagingAndSortingRepository<Category,
@RestResource(path = "listForAccount") @RestResource(path = "listForAccount")
List<Category> findByAccountIdOrderByPositionAsc(@Param("accountId") Long accountId); List<Category> findByAccountIdOrderByPositionAsc(@Param("accountId") Long accountId);
// http://localhost:8084/api/categories/search/expenseLevel?accountId=1&categoryId=1 // http://localhost:8084/api/categories/search/expenseLevelYear?accountId=1&categoryId=1
@RestResource(path = "expenseLevel") @RestResource(path = "expenseLevelYear")
@Query("SELECT sum(t.amount) FROM Transaction t WHERE t.account.id = :accountId AND t.category.id = :categoryId and DATE > (CURRENT_DATE() - DAY_OF_YEAR(CURRENT_DATE()))") @Query("SELECT sum(t.amount) FROM Transaction t WHERE t.account.id = :accountId AND t.category.id = :categoryId and DATE > (CURRENT_DATE() - DAY_OF_YEAR(CURRENT_DATE()))")
Integer getExpenseLevelForCategory(@Param("accountId") Long accountId, @Param("categoryId") Long categoryId); Double getYearExpenseLevelForCategory(@Param("accountId") Long accountId, @Param("categoryId") Long categoryId);
// http://localhost:8084/api/categories/search/expenseLevelMonth?accountId=2&categoryId=5
@RestResource(path = "expenseLevelMonth")
@Query("SELECT sum(t.amount) FROM Transaction t WHERE t.account.id = :accountId AND t.category.id = :categoryId and DATE > (CURRENT_DATE() - DAY_OF_MONTH(CURRENT_DATE()))")
Double getMonthExpenseLevelForCategory(@Param("accountId") Long accountId, @Param("categoryId") Long categoryId);
@PreAuthorize("hasRole('ROLE_ADMIN')") @PreAuthorize("hasRole('ROLE_ADMIN')")
@Override @Override
+1 -1
View File
@@ -73,6 +73,6 @@ INSERT INTO Transaction (id, amount, account_id, category_id, date, description,
INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 3, '2019-10-01', 'Transaction28', null); Commit; INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 3, '2019-10-01', 'Transaction28', null); Commit;
INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 1, '2019-10-01', 'Transaction29', null); Commit; INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 1, '2019-10-01', 'Transaction29', null); Commit;
INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 3, '2019-10-01', 'Transaction30', null); Commit; INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 3, '2019-10-01', 'Transaction30', null); Commit;
INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, 1.50, 2, 5, CURRENT_TIMESTAMP()+1, 'LAST Transaction', null); Commit; INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, 1.90, 2, 5, CURRENT_TIMESTAMP()+1, 'LAST Transaction', null); Commit;
--SCRIPT TO 'h2export.sql'; --SCRIPT TO 'h2export.sql';