From 8267613923f006a9f62e8e4828431d080aa0709a Mon Sep 17 00:00:00 2001 From: Tilman Date: Sun, 10 Nov 2019 00:59:31 +0100 Subject: [PATCH] Show budget, pt. 2 --- README.md | 2 ++ src/main/resources/static/app/controllers.js | 23 +++++++++++++++---- .../static/app/transaction-list.html | 4 +++- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 23dc424..c66b633 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,8 @@ curl --user adam@mail.com:test -i -X DELETE http://localhost:8080/transactions/4 - account direkt in Transaction anzeigen http://docs.spring.io/spring-data/rest/docs/current/reference/html/#projections-excerpts.excerpting-commonly-accessed-data --> mit neuer Projektion: keine zusätzlichen GET-Requests für Creditor und Category, account per Parameter filtern (wie getDescriptionsByAccount), findFirst10 kann entfernt werden +SELECT sum(t.amount) FROM Transaction t WHERE t.account_id = 1 AND t.category_id = 5 and DATE > (CURRENT_DATE() - DAY_OF_YEAR(CURRENT_DATE())) + # Test-Datenbank lokal erreichbar machen: diff --git a/src/main/resources/static/app/controllers.js b/src/main/resources/static/app/controllers.js index 0de12af..25f17d2 100644 --- a/src/main/resources/static/app/controllers.js +++ b/src/main/resources/static/app/controllers.js @@ -105,18 +105,33 @@ transactionControllers.controller('TransactionListCtrl', [ '$scope', '$routePara $scope.checkCategory = function() { // get current expense level for category - $scope.transaction.category.percentage = 0; + $scope.transaction.category.percentageMtl = 0; + $scope.transaction.category.spentMtl = 0; + $scope.transaction.category.budgetMtl = ($scope.transaction.category.budget / 12).toFixed(0); + $scope.transaction.category.percentageYrl = 0; + $scope.transaction.category.spentYrl = 0; // https://stackoverflow.com/a/30119263 - var budgetInfo = $resource('/api/categories/search/expenseLevelYear', { accountId: $scope.account.id, categoryId: $scope.transaction.category.id }, {'getText': { + var expenseInfoMtl = $resource('/api/categories/search/expenseLevelMonth', { accountId: $scope.account.id, categoryId: $scope.transaction.category.id }, {'getText': { transformResponse: function(data, headersGetter, status) { return {value: data}; }}}).getText(); - budgetInfo.$promise.then(function(data) { - $scope.transaction.category.percentage = parseFloat(budgetInfo.value) + 5; + expenseInfoMtl.$promise.then(function(data) { + $scope.transaction.category.spentMtl = (-expenseInfoMtl.value).toFixed(0); + $scope.transaction.category.percentageMtl = (-expenseInfoMtl.value / ($scope.transaction.category.budgetMtl / 100)).toFixed(0); // console.log(budgetInfo.value); }); + var expenseInfoYrl = $resource('/api/categories/search/expenseLevelMonth', { accountId: $scope.account.id, categoryId: $scope.transaction.category.id }, {'getText': { + transformResponse: function(data, headersGetter, status) { + return {value: data}; + }}}).getText(); + expenseInfoYrl.$promise.then(function(data) { + $scope.transaction.category.spentYrl = (-expenseInfoYrl.value).toFixed(0); + $scope.transaction.category.percentageYrl = (-expenseInfoYrl.value / ($scope.transaction.category.budget / 100)).toFixed(0); + }); + + diff --git a/src/main/resources/static/app/transaction-list.html b/src/main/resources/static/app/transaction-list.html index 4bf1a0a..9b9c7a5 100644 --- a/src/main/resources/static/app/transaction-list.html +++ b/src/main/resources/static/app/transaction-list.html @@ -85,7 +85,9 @@
- Budget: + Monat: / € (%) +
+ Jahr: / € (%)