reset outstandings

This commit is contained in:
2016-07-14 00:27:49 +02:00
parent a3d170be77
commit 828ca7a228
3 changed files with 27 additions and 5 deletions
+23 -4
View File
@@ -36,9 +36,13 @@ transactionControllers.controller('TransactionListCtrl', [ '$scope', '$location'
$scope.accountUsers[i].outstandingSum = 0.0;
for (j = 0; j < data[i]._embedded.transactions.length; j++) {
$scope.accountUsers[i].outstandings[j] = new Object();
$scope.accountUsers[i].outstandings[j].date = data[i]._embedded.transactions[j].date;
$scope.accountUsers[i].outstandings[j].description = data[i]._embedded.transactions[j].description;
$scope.accountUsers[i].outstandings[j].href = data[i]._embedded.transactions[j]._links.self.href;
$scope.accountUsers[i].outstandings[j].category = data[i]._embedded.transactions[j].category.name;
if ($scope.accountUsers[i].outstandings[j].category === 'Private Entnahme') { // magic strings ftw
@@ -236,7 +240,7 @@ transactionControllers.controller('TransactionListCtrl', [ '$scope', '$location'
});
};
$scope.openExpenses = function(user) {
$scope.openOutstandings = function(user) {
var modalInstance = $uibModal.open({
templateUrl: 'outstandingsTemplate.html',
controller: 'OutstandingsModalCtrl',
@@ -246,7 +250,7 @@ transactionControllers.controller('TransactionListCtrl', [ '$scope', '$location'
});
modalInstance.result.then(function() {
refreshExpenses();
$scope.refreshList();
}, function () {
$log.info('OutstandingsModal dismissed ' + new Date());
});
@@ -309,7 +313,7 @@ transactionControllers.controller('DetailsModalCtrl', [ '$scope', '$resource', '
}
} ]);
transactionControllers.controller('OutstandingsModalCtrl', [ '$scope', '$uibModalInstance', 'accountUser', function($scope, $uibModalInstance, accountUser) {
transactionControllers.controller('OutstandingsModalCtrl', [ '$scope', '$uibModalInstance', '$http', '$resource', '$q', 'accountUser', function($scope, $uibModalInstance, $http, $resource, $q, accountUser) {
$scope.accountUser = accountUser;
@@ -322,6 +326,21 @@ transactionControllers.controller('OutstandingsModalCtrl', [ '$scope', '$uibModa
};
$scope.clearOutstandings = function() {
// TODO
var promises = new Array($scope.accountUser.outstandings.length);
for (i = 0; i < $scope.accountUser.outstandings.length; i++) {
if ($scope.accountUser.outstandings[i].category === 'Private Entnahme') {
// delete withdrawals
var resource = $resource($scope.accountUser.outstandings[i].href).remove();
promises[i] = resource.$promise;
}
else {
// remove creditor from expenses
promises[i] = $http.patch($scope.accountUser.outstandings[i].href, '{ "creditor" : "" }');
}
}
$q.all(promises).then(function(data) {
$uibModalInstance.close('cleared outstandings');
});
}
} ]);
+3
View File
@@ -4,6 +4,9 @@ transactionServices.factory('Transaction', [ '$resource', function($resource) {
return $resource('/transactions/:id', { id: '@id' }, {
update : {
method : 'PUT'
},
patch : {
method : 'PATCH'
}
});
} ]);
@@ -100,7 +100,7 @@
</div>
<div style="margin-top: 2em; text-align: center;">
<span ng-repeat="user in accountUsers" ng-click="openExpenses(user)" class="clickable">{{user.name}} {{user.outstandingAmount}}&nbsp;<br/></span>
<span ng-repeat="user in accountUsers" ng-click="openOutstandings(user)" class="clickable">{{user.name}} {{user.outstandingAmount}}&nbsp;<br/></span>
</div>