Bill change should be working

Reduce quantity should be working.
This commit is contained in:
2020-10-11 20:53:43 +05:30
parent 73f83f1aa7
commit b7f382cac8
52 changed files with 283 additions and 641 deletions

View File

@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';
import { MathService } from './math.service';
describe('MathService', () => {
let service: MathService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(MathService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});

View File

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