Added: Mathjs for evaluating expressions in journal amount
This commit is contained in:
@ -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,
|
||||
|
||||
Reference in New Issue
Block a user