Number formatting, show account selector only if several are available

This commit is contained in:
2016-07-11 22:48:40 +02:00
parent e7a053f596
commit 6be5da231d
4 changed files with 44 additions and 15 deletions
+20 -12
View File
@@ -1,9 +1,17 @@
var transactionControllers = angular.module('transactionControllers', ['ngResource']);
function amountToNumber(amount) {
amount = amount.toString().replace(',', '.');
if (amount.charAt(0) !== '+' && amount.charAt(0) !== '-') {
amount = '-' + amount;
var number = amount.toString().replace(',', '.');
if (number.charAt(0) !== '+' && number.charAt(0) !== '-') {
number = '-' + number;
}
return number;
}
function numberToAmount(number) {
var amount = number.toFixed(2).toString().replace('.', ',');
if (amount.charAt(0) !== '-') {
amount = "+" + amount;
}
return amount;
}
@@ -83,6 +91,10 @@ transactionControllers.controller('TransactionListCtrl', [ '$scope', '$location'
$scope.nextPageAvailable = (transactions.page.totalPages !== transactions.page.number + 1);
$scope.prevPageAvailable = (transactions.page.number > 0);
$scope.pageNumber = transactions.page.number;
for (i = 0; i < $scope.transactions.length; i++) {
$scope.transactions[i].amount = numberToAmount($scope.transactions[i].amount);
}
});
refreshExpenses();
@@ -199,6 +211,10 @@ transactionControllers.controller('TransactionListCtrl', [ '$scope', '$location'
$scope.pageNumber++;
var transactions = $resource('http://localhost:8080/transactions/search/forAccount', { accountId: $scope.account.id, size: $scope.pageSize, sort: 'date,desc', page: $scope.pageNumber }).get();
transactions.$promise.then(function(data) {
for (i = 0; i < transactions._embedded.transactions.length; i++) {
transactions._embedded.transactions[i].amount = numberToAmount(transactions._embedded.transactions[i].amount);
}
$scope.transactions = $scope.transactions.concat(transactions._embedded.transactions);
$scope.nextPageAvailable = (transactions.page.totalPages !== transactions.page.number + 1);
$scope.prevPageAvailable = (transactions.page.number > 0);
@@ -272,15 +288,7 @@ transactionControllers.controller('DetailsModalCtrl', [ '$scope', '$resource', '
var transaction = Transaction.get({ id: transactionId });
transaction.$promise.then(function(data) {
transaction.amount = transaction.amount.toFixed(2).toString().replace('.', ',');
if (transaction.amount.charAt(0) === '-') {
transaction.amount = transaction.amount.substr(1);
}
else {
transaction.amount = "+" + transaction.amount;
}
transaction.amount = numberToAmount(transaction.amount);
transaction.date = new Date(transaction.date);
transaction.creditor = $resource(transaction._links.creditor.href).get();
transaction.category = $resource(transaction._links.category.href).get();