sum up expenses and withdrawals
This commit is contained in:
@@ -30,7 +30,7 @@ public interface TransactionRepository extends PagingAndSortingRepository<Transa
|
||||
@Query("SELECT t FROM Transaction t INNER JOIN t.account a WHERE a.id = :accountId AND t.description LIKE :prefix% ORDER BY t.date DESC")
|
||||
Page<Transaction> getDescriptionsByAccount(@Param("accountId") Long accountId, @Param("prefix") String prefix, Pageable pageable);
|
||||
|
||||
@RestResource(path = "outstandings")
|
||||
@RestResource(path = "expenses")
|
||||
@Query("SELECT t FROM Transaction t INNER JOIN t.account a WHERE a.id = :accountId AND t.creditor.id = :userId ORDER BY t.date DESC")
|
||||
Page<Transaction> getTransactionsForCreditorByAccount(@Param("accountId") Long accountId, @Param("userId") Long userId, Pageable pageable);
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import de.tilman.transactions.domain.Withdrawal;
|
||||
public interface WithdrawalRepository extends PagingAndSortingRepository<Withdrawal, Long> {
|
||||
|
||||
@RestResource(path = "forAccount")
|
||||
@Query("SELECT w FROM Withdrawal w INNER JOIN w.account a WHERE a.id = :accountId AND w.user.id = :userId ORDER BY t.date DESC")
|
||||
@Query("SELECT w FROM Withdrawal w INNER JOIN w.account a WHERE a.id = :accountId AND w.user.id = :userId ORDER BY w.date DESC")
|
||||
Page<Withdrawal> getWithdrawalsForUserByAccount(@Param("accountId") Long accountId, @Param("userId") Long userId, Pageable pageable);
|
||||
|
||||
}
|
||||
|
||||
@@ -37,26 +37,52 @@ transactionControllers.controller('TransactionListCtrl', [ '$scope', '$location'
|
||||
accountUsers.$promise.then(function(data) {
|
||||
$scope.accountUsers = accountUsers._embedded.users;
|
||||
|
||||
// get outstandings for all users of the account
|
||||
// initialize attributes for outstanding amounts
|
||||
for (i = 0; i < $scope.accountUsers.length; i++) {
|
||||
$scope.accountUsers[i].outstandings = 0.0;
|
||||
}
|
||||
|
||||
// get expenses 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();
|
||||
var resource = $resource('/transactions/search/expenses', { 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;
|
||||
var expenseSum = 0;
|
||||
for (j = 0; j < data[i]._embedded.transactions.length; j++) {
|
||||
outstandingSum = outstandingSum + data[i]._embedded.transactions[j].amount;
|
||||
expenseSum = expenseSum + data[i]._embedded.transactions[j].amount;
|
||||
}
|
||||
$scope.accountUsers[i].outstandings = outstandingSum;
|
||||
console.log('$scope.userinfo.outstandings: ' + $scope.accountUsers[i].outstandings);
|
||||
$scope.accountUsers[i].outstandings -= expenseSum;
|
||||
//console.log('Expenses by ' + $scope.accountUsers[i].name + ': ' + expenseSum);
|
||||
}
|
||||
});
|
||||
|
||||
// get withdrawals for all users of the account
|
||||
var promises = new Array($scope.accountUsers.length);
|
||||
for (i = 0; i < $scope.accountUsers.length; i++) {
|
||||
var resource = $resource('/withdrawals/search/forAccount', { 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 withdrawnSum = 0;
|
||||
for (j = 0; j < data[i]._embedded.withdrawals.length; j++) {
|
||||
withdrawnSum = withdrawnSum + data[i]._embedded.withdrawals[j].amount;
|
||||
}
|
||||
$scope.accountUsers[i].outstandings -= withdrawnSum;
|
||||
//console.log('Withdrawals by ' + $scope.accountUsers[i].name + ': ' + withdrawnSum);
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
// TODO for some reason this does not work upon reload
|
||||
document.getElementsByName('expenseBy')[0].checked = true;
|
||||
|
||||
}
|
||||
|
||||
$scope.checkCategory = function() {
|
||||
@@ -139,7 +165,6 @@ transactionControllers.controller('TransactionListCtrl', [ '$scope', '$location'
|
||||
newWithdrawal.$save(function(withdrawal) {
|
||||
$scope.refreshList();
|
||||
$scope.lastSubmission = newWithdrawal;
|
||||
console.log(newWithdrawal);
|
||||
});
|
||||
|
||||
return;
|
||||
@@ -148,13 +173,16 @@ transactionControllers.controller('TransactionListCtrl', [ '$scope', '$location'
|
||||
// via Resource (might be moved into a service)
|
||||
var Transaction = $resource('/transactions');
|
||||
|
||||
console.log('Creditor:');
|
||||
console.log($scope.transaction.creditor);
|
||||
|
||||
var newTransaction = new Transaction({
|
||||
"account" : $scope.account._links.self.href,
|
||||
"amount" : amount,
|
||||
"date" : $scope.transaction.date,
|
||||
"description" : $scope.transaction.description,
|
||||
"category" : $scope.transaction.category._links.self.href,
|
||||
"creditor" : $scope.creditor
|
||||
"creditor" : $scope.transaction.creditor
|
||||
});
|
||||
|
||||
newTransaction.$save(function(transaction) {
|
||||
|
||||
@@ -34,8 +34,14 @@
|
||||
</tr>
|
||||
<tr>
|
||||
<td align='right'>Auslage:</td>
|
||||
<td><label class='userLabel'><input name='expenseBy' type='radio' checked='checked' />Keine</label> <label
|
||||
ng-repeat="user in accountUsers" class='userLabel'><input name='expenseBy' type='radio' />{{user.name}}</label></td>
|
||||
<td>
|
||||
<!-- label class='userLabel'><input name='expenseBy' ng-model='transaction.creditor' ng-value='none' type='radio' checked='checked' />Keine</label -->
|
||||
<!-- label ng-repeat="user in accountUsers" class='userLabel'><input name='expenseBy' ng-model='$parent.transaction.creditor' ng-value='{{user.name}}' type='radio' />{{user.name}}</label -->
|
||||
|
||||
<label class='userLabel'><input id='noCreditorRadioButton' name='expenseBy' ng-model='transaction.creditor' type='radio' value='' checked='checked' />Keine</label>
|
||||
<label class='userLabel' ng-repeat="user in accountUsers"><input name='expenseBy' ng-model='$parent.transaction.creditor' type='radio' value="{{user._links.self.href}}" />{{user.name}}</label>
|
||||
</td>
|
||||
|
||||
</tr>
|
||||
<tr>
|
||||
<td align='center' colspan='2'><input type="submit" ng-disabled="form.amount.$error.pattern" /></td>
|
||||
@@ -58,8 +64,8 @@
|
||||
</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 style="margin-top: 2em; text-align: center;">
|
||||
<span ng-repeat="user in accountUsers">{{user.name}} {{user.outstandings | number : 2}} €<br/></span>
|
||||
</div>
|
||||
|
||||
<!-- div>
|
||||
|
||||
Reference in New Issue
Block a user