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:41:17 +05:30
parent cefb3ebdcc
commit cfeef1795d
20 changed files with 202 additions and 120 deletions

View File

@ -0,0 +1,26 @@
import { Injectable } from '@angular/core';
import { evaluate, round } from 'mathjs';
@Injectable({
providedIn: 'root',
})
export class MathService {
constructor() {}
journalAmount(amount: string = '', debit: number): any {
const val = this.parseAmount(amount, 2);
if (val < 0) {
debit *= -1;
}
return { debit: debit, amount: Math.abs(val) };
}
parseAmount(amount: string = '', rounding: number = 2): number {
const cleaned = ('' + amount).replace(new RegExp('(₹[s]*)|(,)|(s)', 'g'), '');
if (cleaned === '') {
return 0;
} else {
return round(evaluate(cleaned), rounding);
}
}
}