sum of expenses
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
var transactionControllers = angular.module('transactionControllers', ['ngResource']);
|
||||
|
||||
transactionControllers.controller('TransactionListCtrl', [ '$scope', '$location', '$resource', function($scope, $location, $resource) {
|
||||
transactionControllers.controller('TransactionListCtrl', [ '$scope', '$location', '$resource', '$q', function($scope, $location, $resource, $q) {
|
||||
|
||||
$scope.refreshList = function() {
|
||||
|
||||
@@ -23,7 +23,6 @@ transactionControllers.controller('TransactionListCtrl', [ '$scope', '$location'
|
||||
|
||||
// get recent transactions
|
||||
var transactions = $resource('/transactions/search/last10', { accountId: $scope.account.id }).get();
|
||||
|
||||
transactions.$promise.then(function(data) {
|
||||
$scope.transactions = transactions._embedded.transactions;
|
||||
|
||||
@@ -37,6 +36,25 @@ transactionControllers.controller('TransactionListCtrl', [ '$scope', '$location'
|
||||
var accountUsers = $resource($scope.account._links.users.href).get();
|
||||
accountUsers.$promise.then(function(data) {
|
||||
$scope.accountUsers = accountUsers._embedded.users;
|
||||
|
||||
// get outstandings for all users of the account
|
||||
var promises = new Array($scope.accountUsers.length);
|
||||
for (i = 0; i < $scope.accountUsers.length; i++) {
|
||||
var resource = $resource('/transactions/search/outstandings', { accountId: $scope.account.id, userId: $scope.accountUsers[i].id }).get();
|
||||
promises[i] = resource.$promise;
|
||||
}
|
||||
|
||||
$q.all(promises).then(function(data) {
|
||||
for (i = 0; i < data.length; i++) {
|
||||
var outstandingSum = 0;
|
||||
for (j = 0; j < data[i]._embedded.transactions.length; j++) {
|
||||
outstandingSum = outstandingSum + data[i]._embedded.transactions[j].amount;
|
||||
}
|
||||
$scope.accountUsers[i].outstandings = outstandingSum;
|
||||
console.log('$scope.userinfo.outstandings: ' + $scope.accountUsers[i].outstandings);
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@@ -57,6 +57,10 @@
|
||||
<td>{{transaction.description}}</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<div style="margin: auto; width: 30 em; text-align: center;">
|
||||
<span ng-repeat="user in accountUsers">{{user.name}} {{user.outstandings}} €<br/></span>
|
||||
</div>
|
||||
|
||||
<!-- div>
|
||||
<pre style="font-size: 75%; color: darkgray;">{{account | json}}</pre>
|
||||
|
||||
Reference in New Issue
Block a user