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:
26
overlord/src/app/shared/math.service.ts
Normal file
26
overlord/src/app/shared/math.service.ts
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user