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
+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;