Receive payment working.

TODO: Nested subscribe in Receive Payment in sales-home-component.ts should be refactored into something more readable.
This commit is contained in:
Amritanshu
2019-08-09 14:55:38 +05:30
parent 6503982897
commit ff8f4ffb16
16 changed files with 315 additions and 64 deletions

View File

@ -2,6 +2,7 @@ import { Injectable } from '@angular/core';
import { MatDialog } from '@angular/material';
import { BehaviorSubject } from 'rxjs';
import { Observable } from 'rxjs/internal/Observable';
import * as math from 'mathjs';
import { Product } from '../core/product';
import { ModifiersComponent } from './modifiers/modifiers.component';
import { ModifierCategoryService } from '../modifier-categories/modifier-category.service';
@ -41,7 +42,7 @@ export class BillService {
productId: i.product.id,
isHappyHour: i.isHappyHour,
isPrinted: true,
info: `${i.product.name} (${i.product.units}) @ ${i.price} - ${i.discount * 100}%`,
info: `${i.product.name} (${i.product.units}) @ ${i.price} - ${math.round(i.discount * 100, 2)}%`,
price: i.price,
quantity: i.quantity,
discount: i.discount,
@ -139,7 +140,7 @@ export class BillService {
this.data.forEach(x=> {
if (!x.isKot) {
x.discount = discounts.find(d => d.id === x.product.saleCategory.id).discount / 100;
x.info = `${x.product.name} (${x.product.units}) @ ${x.price} - ${x.discount * 100}%`;
x.info = `${x.product.name} (${x.product.units}) @ ${x.price} - ${math.round(x.discount * 100, 2)}%`;
}
});
this.dataObs.next(this.data);
@ -185,4 +186,21 @@ export class BillService {
);
}
amount() {
return math.round(this.bill.kots.reduce(
(ka: number, k: Kot) => ka + k.inventories.reduce(
(ca: number, c: Inventory) => ca + ((c.isHappyHour ? 0 : c.price) * c.quantity * (1 - c.discount) * (1 + c.taxRate))
, 0)
, 0))
}
type() {
return this.bill.voucherType;
}
receivePayment(amounts: { id: string; name: string; amount: number }[]) {
return this.ser.receivePayment(this.bill.id, amounts, true).pipe(
tap(x => console.log(x))
);
}
}