removed Withdrawal entity

This commit is contained in:
2016-07-13 23:53:55 +02:00
parent 2c92dd00fe
commit a3d170be77
10 changed files with 76 additions and 214 deletions
+4
View File
@@ -61,6 +61,10 @@ label {
cursor: pointer;
}
.color-black {
color: black;
}
.color-red {
color: red;
}
+26 -77
View File
@@ -23,53 +23,34 @@ transactionControllers.controller('TransactionListCtrl', [ '$scope', '$location'
accountUsers.$promise.then(function(data) {
$scope.accountUsers = accountUsers._embedded.users;
// initialize attributes for outstanding amounts
for (i = 0; i < $scope.accountUsers.length; i++) {
$scope.accountUsers[i].outstandingSum = 0.0;
}
// get expenses for all users of the account
// get outstandings (expenses and 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('/transactions/search/expenses', { accountId: $scope.account.id, userId: $scope.accountUsers[i].id }).get();
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++) {
$scope.accountUsers[i].expenses = new Array(data[i]._embedded.transactions.length);
var expenseSum = 0;
$scope.accountUsers[i].outstandings = new Array(data[i]._embedded.transactions.length);
$scope.accountUsers[i].outstandingSum = 0.0;
for (j = 0; j < data[i]._embedded.transactions.length; j++) {
$scope.accountUsers[i].expenses[j] = new Object();
$scope.accountUsers[i].expenses[j].date = data[i]._embedded.transactions[j].date;
$scope.accountUsers[i].expenses[j].category = data[i]._embedded.transactions[j].category.name;
$scope.accountUsers[i].expenses[j].amount = numberToAmount(data[i]._embedded.transactions[j].amount);
$scope.accountUsers[i].expenses[j].description = data[i]._embedded.transactions[j].description;
expenseSum = expenseSum + data[i]._embedded.transactions[j].amount;
$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].category = data[i]._embedded.transactions[j].category.name;
if ($scope.accountUsers[i].outstandings[j].category === 'Private Entnahme') { // magic strings ftw
$scope.accountUsers[i].outstandingSum += data[i]._embedded.transactions[j].amount;
$scope.accountUsers[i].outstandings[j].amount = numberToAmount(data[i]._embedded.transactions[j].amount);
}
else {
$scope.accountUsers[i].outstandingSum -= data[i]._embedded.transactions[j].amount;
$scope.accountUsers[i].outstandings[j].amount = numberToAmount(-data[i]._embedded.transactions[j].amount);
}
}
$scope.accountUsers[i].outstandingSum -= expenseSum;
$scope.accountUsers[i].outstandingAmount = numberToAmount($scope.accountUsers[i].outstandingSum);
}
});
// 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++) {
$scope.accountUsers[i].withdrawals = new Array(data[i]._embedded.withdrawals.length);
var withdrawnSum = 0;
for (j = 0; j < data[i]._embedded.withdrawals.length; j++) {
$scope.accountUsers[i].withdrawals[j] = new Object();
$scope.accountUsers[i].withdrawals[j].date = data[i]._embedded.withdrawals[j].date;
$scope.accountUsers[i].withdrawals[j].amount = numberToAmount(data[i]._embedded.withdrawals[j].amount);
withdrawnSum = withdrawnSum + data[i]._embedded.withdrawals[j].amount;
}
$scope.accountUsers[i].outstandingSum -= withdrawnSum;
$scope.accountUsers[i].outstandingAmount = numberToAmount($scope.accountUsers[i].outstandingSum);
}
});
@@ -116,7 +97,7 @@ transactionControllers.controller('TransactionListCtrl', [ '$scope', '$location'
var userLabels = document.getElementsByClassName('userLabel');
// if this is selected to be a withdrawal, preselect the current user and lock the radio buttons
if ($scope.transaction.category.id == -1) {
if ($scope.transaction.category.name === 'Private Entnahme') {
for (i = 0; i < userLabels.length; i++) {
console.log(userLabels[i].innerHTML.substr(-$scope.userinfo.name.length-6));
if (userLabels[i].innerHTML.indexOf($scope.userinfo.name) >= 0) {
@@ -155,47 +136,16 @@ transactionControllers.controller('TransactionListCtrl', [ '$scope', '$location'
var categories = $resource('/categories/search/listForAccount', { accountId: $scope.accounts[0].id }).get();
categories.$promise.then(function(data) {
$scope.categories = categories._embedded.categories;
//$scope.categories.push({id: -1, name: '────────────────', position: 9999, disabled: true});
$scope.categories.push({id: -1, name: 'private Entnahme', position: 10000, _links: { self: {href: 'withdrawal'}}});
$scope.refreshList();
});
});
});
}
$scope.postTransaction = function() {
var amount = amountToNumber($scope.transaction.amount);
// handle withdrawals
if ($scope.transaction.category._links.self.href === 'withdrawal') {
if (amount.charAt(0) === '-') {
amount = amount.substr(1);
}
var Withdrawal = $resource('/withdrawals');
var newWithdrawal = new Withdrawal({
"account" : $scope.account._links.self.href,
"amount" : amount,
"date" : $scope.transaction.date,
"user" : $scope.userinfo._links.self.href
});
newWithdrawal.$save(function(withdrawal) {
$scope.refreshList();
$scope.lastSubmission = newWithdrawal;
});
return;
}
var newTransaction = new Transaction({
"account" : $scope.account._links.self.href,
"amount" : amount,
"amount" : amountToNumber($scope.transaction.amount),
"date" : $scope.transaction.date,
"description" : $scope.transaction.description,
"category" : $scope.transaction.category._links.self.href,
@@ -206,7 +156,6 @@ transactionControllers.controller('TransactionListCtrl', [ '$scope', '$location'
$scope.refreshList();
$scope.lastSubmission = newTransaction;
});
};
$scope.deleteLastSubmission = function() {
@@ -289,8 +238,8 @@ transactionControllers.controller('TransactionListCtrl', [ '$scope', '$location'
$scope.openExpenses = function(user) {
var modalInstance = $uibModal.open({
templateUrl: 'expensesTemplate.html',
controller: 'ExpensesModalCtrl',
templateUrl: 'outstandingsTemplate.html',
controller: 'OutstandingsModalCtrl',
resolve: {
accountUser: user
}
@@ -299,7 +248,7 @@ transactionControllers.controller('TransactionListCtrl', [ '$scope', '$location'
modalInstance.result.then(function() {
refreshExpenses();
}, function () {
$log.info('ExpensesModal dismissed ' + new Date());
$log.info('OutstandingsModal dismissed ' + new Date());
});
};
@@ -325,7 +274,7 @@ transactionControllers.controller('DetailsModalCtrl', [ '$scope', '$resource', '
for (i = 0; i < $scope.categories.length; i++) {
if ($scope.categories[i].name == $scope.transaction.category.name) {
$scope.transaction.category = $scope.categories[i];
$scope.transaction.category = $scope.categories[i];
break;
}
}
@@ -360,7 +309,7 @@ transactionControllers.controller('DetailsModalCtrl', [ '$scope', '$resource', '
}
} ]);
transactionControllers.controller('ExpensesModalCtrl', [ '$scope', '$uibModalInstance', 'accountUser', function($scope, $uibModalInstance, accountUser) {
transactionControllers.controller('OutstandingsModalCtrl', [ '$scope', '$uibModalInstance', 'accountUser', function($scope, $uibModalInstance, accountUser) {
$scope.accountUser = accountUser;
@@ -91,7 +91,7 @@
<tr ng-repeat="transaction in transactions" ng-click="openDetails(transaction)" class="clickable">
<td>{{transaction.date | date:'dd.MM.yyyy'}}</td>
<td>{{transaction.category.name}}</td>
<td align="right" class="{{transaction.creditor.name ? 'creditor-' + transaction.creditor.id : ''}}">{{transaction.amount}}&nbsp;&euro;</td>
<td align="right" class="{{transaction.creditor.name ? 'creditor-' + transaction.creditor.id : ''}}"><span ng-class="transaction.amount.charAt(0) === '+' ? 'color-green' : 'color-black'">{{transaction.amount}}&nbsp;&euro;</span></td>
<td>{{transaction.description}}</td>
</tr>
</table>
@@ -176,13 +176,12 @@
<!-- pre style="font-size: 75%; color: black;">{{transaction | json}}</pre -->
</script>
<script type="text/ng-template" id="expensesTemplate.html">
<script type="text/ng-template" id="outstandingsTemplate.html">
<div class="modal-header">
<h3 class="modal-title">{{accountUser.name}} <span style="margin: 0" ng-class="accountUser.outstandingSum >= 0 ? 'color-green' : 'color-red'">{{accountUser.outstandingAmount}}&nbsp;</span></h3>
<h3 class="modal-title">{{accountUser.name}} <span ng-class="accountUser.outstandingSum >= 0 ? 'color-green' : 'color-red'">{{accountUser.outstandingAmount}}&nbsp;</span></h3>
</div>
<div class="modal-body">
<div ng-show="accountUser.expenses.length > 0">
<h4 class="modal-title">Auslagen</h4>
<div ng-show="accountUser.outstandings.length > 0">
<table class="listing">
<tr>
<th>Datum</th>
@@ -190,30 +189,16 @@
<th>Betrag</th>
<th>Beschreibung</th>
</tr>
<tr ng-repeat="expense in accountUser.expenses">
<td>{{expense.date | date:'dd.MM.yyyy'}}</td>
<td>{{expense.category}}</td>
<td align="right">{{expense.amount}}&nbsp;&euro;</td>
<td>{{expense.description}}</td>
<tr ng-repeat="outstanding in accountUser.outstandings">
<td>{{outstanding.date | date:'dd.MM.yyyy'}}</td>
<td>{{outstanding.category}}</td>
<td align="right"><span ng-class="outstanding.amount.charAt(0) === '+' ? 'color-green' : 'color-red'">{{outstanding.amount}}&nbsp;&euro;</span></td>
<td>{{outstanding.description}}</td>
</tr>
</table>
</div>
<div ng-show="accountUser.withdrawals.length > 0">
<h4 class="modal-title" style="margin-top: 3.5ex;">Entnahmen</h4>
<table class="listing">
<tr>
<th>Datum</th>
<th>Betrag</th>
</tr>
<tr ng-repeat="withdrawal in accountUser.withdrawals">
<td>{{withdrawal.date | date:'dd.MM.yyyy'}}</td>
<td align="right">{{withdrawal.amount}}&nbsp;&euro;</td>
</tr>
</table>
</div>
<div ng-show="accountUser.expenses.length == 0 && accountUser.withdrawals.length == 0">
<div ng-show="accountUser.outstandings.length == 0">
<i>Keine Auslagen oder Entnahmen für {{accountUser.name}}</i>
</div>