Feature: Allow math expressions on all journal inputs and also round them properly.

Chore:
  Prettied index.html, main.ts and styles.css
  Updated Dependencies
This commit is contained in:
2020-10-07 18:42:22 +05:30
parent cefb3ebdcc
commit cfeef1795d
20 changed files with 202 additions and 120 deletions
+17 -12
View File
@@ -10,7 +10,8 @@ import { VoucherService } from '../core/voucher.service';
import { AccountService } from '../core/account.service';
import { DbFile, Journal, Voucher } from '../core/voucher';
import * as moment from 'moment';
import { evaluate } from 'mathjs';
import { round } from 'mathjs';
import { MathService } from '../shared/math.service';
import { AuthService } from '../auth/auth.service';
import { ConfirmDialogComponent } from '../shared/confirm-dialog/confirm-dialog.component';
import { ToasterService } from '../core/toaster.service';
@@ -48,6 +49,7 @@ export class PaymentComponent implements OnInit, AfterViewInit, OnDestroy {
private hotkeys: HotkeysService,
private toaster: ToasterService,
private auth: AuthService,
private math: MathService,
private ser: VoucherService,
private accountSer: AccountService,
) {
@@ -133,7 +135,7 @@ export class PaymentComponent implements OnInit, AfterViewInit, OnDestroy {
}
addRow() {
const amount = this.rowAmount(this.form.get('addRow').value.amount);
const amount = this.math.parseAmount(this.form.get('addRow').value.amount, 2);
const debit = 1;
if (this.account === null || amount <= 0) {
return;
@@ -157,15 +159,15 @@ export class PaymentComponent implements OnInit, AfterViewInit, OnDestroy {
this.resetAddRow();
this.updateView();
}
rowAmount(amount: string = ''): number {
try {
amount = amount.replace(new RegExp('(₹[s]*)|(,)|(s)', 'g'), '');
return evaluate(amount);
} catch {
return 0;
}
}
//
// rowAmount(amount: string = ''): number {
// try {
// amount = amount.replace(new RegExp('(₹[s]*)|(,)|(s)', 'g'), '');
// return round(evaluate(amount), 2);
// } catch {
// return 0;
// }
// }
resetAddRow() {
this.form.get('addRow').reset({
@@ -182,7 +184,10 @@ export class PaymentComponent implements OnInit, AfterViewInit, OnDestroy {
updateView() {
const journals = this.voucher.journals.filter((x) => x.debit === 1);
this.journalObservable.next(journals);
this.paymentJournal.amount = Math.abs(journals.map((x) => x.amount).reduce((p, c) => p + c, 0));
this.paymentJournal.amount = round(
Math.abs(journals.map((x) => x.amount).reduce((p, c) => p + c, 0)),
2,
);
this.form.get('paymentAmount').setValue(this.paymentJournal.amount);
}