Show budget, pt. 2

This commit is contained in:
2019-11-10 00:59:31 +01:00
parent d1898e7f38
commit 8267613923
3 changed files with 24 additions and 5 deletions
+2
View File
@@ -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:
+19 -4
View File
@@ -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);
});
@@ -85,7 +85,9 @@
</div>
<div class="budgetArea">
Budget: <span class="budgetCalculation"><span ng-bind="transaction.category.budget"></span> <span ng-bind="transaction.category.percentage"></span></span>
Monat: <span class="budgetCalculation"><span ng-bind="transaction.category.spentMtl"></span> / <span ng-bind="transaction.category.budgetMtl"></span> € (<span ng-bind="transaction.category.percentageMtl"></span>%)</span>
<br/>
Jahr: <span class="budgetCalculation"><span ng-bind="transaction.category.spentYrl"></span> / <span ng-bind="transaction.category.budget"></span> € (<span ng-bind="transaction.category.percentageYrl"></span>%)</span>
</div>
<div class="row">