Added: Mathjs for evaluating expressions in journal amount

This commit is contained in:
tanshu
2018-06-29 13:32:52 +05:30
parent c6272762da
commit ede445ac1f
4 changed files with 42 additions and 8 deletions

View File

@ -9,6 +9,7 @@ import {VoucherService} from '../journal/voucher.service';
import {AccountService} from '../account/account.service';
import {DbFile, Journal, Voucher} from '../journal/voucher';
import * as moment from 'moment';
import * as math from 'mathjs';
import {AuthService} from '../auth/auth.service';
import {ConfirmDialogComponent} from '../shared/confirm-dialog/confirm-dialog.component';
import {ToasterService} from '../core/toaster.service';
@ -46,6 +47,7 @@ export class ReceiptComponent implements OnInit, AfterViewInit {
private ser: VoucherService,
private accountSer: AccountService
) {
this.account = null;
this.createForm();
this.listenToAccountAutocompleteChange();
this.listenToReceiptAccountChange();
@ -87,7 +89,7 @@ export class ReceiptComponent implements OnInit, AfterViewInit {
}
addRow() {
const amount = +(this.form.get('addRow').value.amount);
const amount = this.rowAmount(this.form.get('addRow').value.amount);
const debit = -1;
if (this.account === null || amount <= 0) {
return;
@ -112,6 +114,14 @@ export class ReceiptComponent implements OnInit, AfterViewInit {
this.updateView();
}
rowAmount(amount: string = ''): number {
try {
return math.eval(amount.trim().replace(',', ''));
} catch {
return 0;
}
}
resetAddRow() {
this.form.get('addRow').reset({
account: null,