Bill change should be working
Reduce quantity should be working.
This commit is contained in:
16
bookie/src/app/shared/math.service.spec.ts
Normal file
16
bookie/src/app/shared/math.service.spec.ts
Normal 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();
|
||||
});
|
||||
});
|
||||
26
bookie/src/app/shared/math.service.ts
Normal file
26
bookie/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 {
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user