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")
|
@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);
|
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")
|
@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);
|
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> {
|
public interface WithdrawalRepository extends PagingAndSortingRepository<Withdrawal, Long> {
|
||||||
|
|
||||||
@RestResource(path = "forAccount")
|
@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);
|
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) {
|
accountUsers.$promise.then(function(data) {
|
||||||
$scope.accountUsers = accountUsers._embedded.users;
|
$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);
|
var promises = new Array($scope.accountUsers.length);
|
||||||
for (i = 0; i < $scope.accountUsers.length; i++) {
|
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;
|
promises[i] = resource.$promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
$q.all(promises).then(function(data) {
|
$q.all(promises).then(function(data) {
|
||||||
for (i = 0; i < data.length; i++) {
|
for (i = 0; i < data.length; i++) {
|
||||||
var outstandingSum = 0;
|
var expenseSum = 0;
|
||||||
for (j = 0; j < data[i]._embedded.transactions.length; j++) {
|
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;
|
$scope.accountUsers[i].outstandings -= expenseSum;
|
||||||
console.log('$scope.userinfo.outstandings: ' + $scope.accountUsers[i].outstandings);
|
//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() {
|
$scope.checkCategory = function() {
|
||||||
@@ -139,7 +165,6 @@ transactionControllers.controller('TransactionListCtrl', [ '$scope', '$location'
|
|||||||
newWithdrawal.$save(function(withdrawal) {
|
newWithdrawal.$save(function(withdrawal) {
|
||||||
$scope.refreshList();
|
$scope.refreshList();
|
||||||
$scope.lastSubmission = newWithdrawal;
|
$scope.lastSubmission = newWithdrawal;
|
||||||
console.log(newWithdrawal);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@@ -148,13 +173,16 @@ transactionControllers.controller('TransactionListCtrl', [ '$scope', '$location'
|
|||||||
// via Resource (might be moved into a service)
|
// via Resource (might be moved into a service)
|
||||||
var Transaction = $resource('/transactions');
|
var Transaction = $resource('/transactions');
|
||||||
|
|
||||||
|
console.log('Creditor:');
|
||||||
|
console.log($scope.transaction.creditor);
|
||||||
|
|
||||||
var newTransaction = new Transaction({
|
var newTransaction = new Transaction({
|
||||||
"account" : $scope.account._links.self.href,
|
"account" : $scope.account._links.self.href,
|
||||||
"amount" : amount,
|
"amount" : amount,
|
||||||
"date" : $scope.transaction.date,
|
"date" : $scope.transaction.date,
|
||||||
"description" : $scope.transaction.description,
|
"description" : $scope.transaction.description,
|
||||||
"category" : $scope.transaction.category._links.self.href,
|
"category" : $scope.transaction.category._links.self.href,
|
||||||
"creditor" : $scope.creditor
|
"creditor" : $scope.transaction.creditor
|
||||||
});
|
});
|
||||||
|
|
||||||
newTransaction.$save(function(transaction) {
|
newTransaction.$save(function(transaction) {
|
||||||
|
|||||||
@@ -34,8 +34,14 @@
|
|||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td align='right'>Auslage:</td>
|
<td align='right'>Auslage:</td>
|
||||||
<td><label class='userLabel'><input name='expenseBy' type='radio' checked='checked' />Keine</label> <label
|
<td>
|
||||||
ng-repeat="user in accountUsers" class='userLabel'><input name='expenseBy' type='radio' />{{user.name}}</label></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>
|
||||||
<tr>
|
<tr>
|
||||||
<td align='center' colspan='2'><input type="submit" ng-disabled="form.amount.$error.pattern" /></td>
|
<td align='center' colspan='2'><input type="submit" ng-disabled="form.amount.$error.pattern" /></td>
|
||||||
@@ -58,8 +64,8 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<div style="margin: auto; width: 30 em; text-align: center;">
|
<div style="margin-top: 2em; text-align: center;">
|
||||||
<span ng-repeat="user in accountUsers">{{user.name}} {{user.outstandings}} €<br/></span>
|
<span ng-repeat="user in accountUsers">{{user.name}} {{user.outstandings | number : 2}} €<br/></span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- div>
|
<!-- div>
|
||||||
|
|||||||
Reference in New Issue
Block a user