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:
tanshu committed 2020-10-07 18:42:22 +05:30
1 parent cefb3ebdcc
commit cfeef1795d
20 files changed
+202 -120

No files matched your search

+7 -17
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';
@@ -46,6 +47,7 @@ export class JournalComponent implements OnInit, AfterViewInit, OnDestroy {
private hotkeys: HotkeysService,
private toaster: ToasterService,
private auth: AuthService,
private math: MathService,
private ser: VoucherService,
private accountSer: AccountService,
) {
@@ -131,7 +133,7 @@ export class JournalComponent implements OnInit, AfterViewInit, OnDestroy {
addRow() {
const formValue = this.form.get('addRow').value;
const amount = this.rowAmount(formValue.amount, +formValue.debit);
const amount = this.math.journalAmount(formValue.amount, +formValue.debit);
if (this.account === null || amount.amount === 0) {
return;
}
@@ -154,22 +156,10 @@ export class JournalComponent implements OnInit, AfterViewInit, OnDestroy {
this.resetAddRow();
}
rowAmount(amount: string = '', debit: number): any {
try {
amount = amount.replace(new RegExp('(₹[s]*)|(,)|(s)', 'g'), '');
const val = evaluate(amount);
if (val < 0) {
debit *= -1;
}
return { debit: debit, amount: Math.abs(val) };
} catch {
return { debit: debit, amount: 0 };
}
}
resetAddRow() {
const amount = Math.abs(
this.voucher.journals.map((x) => x.debit * x.amount).reduce((p, c) => p + c),
const amount = round(
Math.abs(this.voucher.journals.map((x) => x.debit * x.amount).reduce((p, c) => p + c)),
2,
);
const debit = this.form.get('addRow').value.debit;
this.form.get('addRow').reset({