Feature: Math Solver for the Amounts in Journal, Payment and Receipt.

This commit is contained in:
tanshu
2016-12-04 13:02:37 +05:30
parent c90651aa8c
commit 0fecc02e1a
5 changed files with 54 additions and 15 deletions

View File

@ -1,6 +1,6 @@
'use strict';
var JournalController = ['$scope', '$location', 'asDateFilter', '$modal', 'uploadedImageResizer', 'voucher', 'Account', function ($scope, $location, asDate, $modal, uploadedImageResizer, voucher, Account) {
var JournalController = ['$scope', '$location', 'asDateFilter', '$modal', 'uploadedImageResizer', 'mathSolver', 'voucher', 'Account', function ($scope, $location, asDate, $modal, uploadedImageResizer, mathSolver, voucher, Account) {
$scope.foAccount = true;
$scope.voucher = voucher;
@ -35,12 +35,18 @@ var JournalController = ['$scope', '$location', 'asDateFilter', '$modal', 'uploa
};
$scope.add = function () {
if (!$scope.account || !$scope.account.LedgerID || !$scope.amount || Number(!$scope.amount)) {
var amount,
oldJournal;
if (!$scope.account || !$scope.account.LedgerID) {
return;
}
var oldJournal = getOld($scope.account.LedgerID, $scope.voucher.Journals);
amount = mathSolver($scope.amount);
if (Number.isNaN(amount) || amount <= 0) {
return;
}
oldJournal = getOld($scope.account.LedgerID, $scope.voucher.Journals);
if (!angular.isUndefined(oldJournal)) {
var amount = (oldJournal.Debit * oldJournal.Amount) + (parseInt($scope.debit) * Number($scope.amount));
amount = (oldJournal.Debit * oldJournal.Amount) + (parseInt($scope.debit) * amount);
if (amount < 0) {
oldJournal.Debit = -1;
oldJournal.Amount = amount * -1;
@ -49,7 +55,7 @@ var JournalController = ['$scope', '$location', 'asDateFilter', '$modal', 'uploa
oldJournal.Amount = amount;
}
} else {
$scope.voucher.Journals.push({Debit: parseInt($scope.debit), Amount: Number($scope.amount), Ledger: $scope.account});
$scope.voucher.Journals.push({Debit: parseInt($scope.debit), Amount: amount, Ledger: $scope.account});
}
delete $scope.account;
delete $scope.amount;