Feature: Allow bills without items so that tables can be seated from the guest book.
Feature: Allow guest book entries to be associated with running vouchers Feature: Allow removing customer from voucher
This commit is contained in:
@ -26,6 +26,7 @@ import { ModifiersComponent } from './modifiers/modifiers.component';
|
||||
export class BillService {
|
||||
public dataObs: BehaviorSubject<BillViewItem[]>;
|
||||
public bill: Bill = new Bill();
|
||||
private originalBill: Bill = new Bill();
|
||||
public grossAmount: BehaviorSubject<number>;
|
||||
public discountAmount: BehaviorSubject<number>;
|
||||
public hhAmount: BehaviorSubject<number>;
|
||||
@ -93,6 +94,7 @@ export class BillService {
|
||||
this.updateTable = updateTable;
|
||||
bill.kots.push(new Kot());
|
||||
this.bill = bill;
|
||||
this.originalBill = JSON.parse(JSON.stringify(this.bill));
|
||||
this.selection.clear();
|
||||
this.displayBill();
|
||||
}
|
||||
@ -223,31 +225,52 @@ export class BillService {
|
||||
this.displayBill();
|
||||
}
|
||||
|
||||
isBillDiffent(bill: Bill, guestBookId: string | null): boolean {
|
||||
const newItems = bill.kots
|
||||
.filter((k: Kot) => k.id === undefined)
|
||||
.reduce((p: number, k: Kot) => p + k.inventories.filter((i) => i.quantity !== 0).length, 0);
|
||||
if (newItems > 0) {
|
||||
return true;
|
||||
}
|
||||
if (guestBookId !== null) {
|
||||
return true;
|
||||
}
|
||||
if (bill.pax != this.originalBill.pax) {
|
||||
return true;
|
||||
}
|
||||
if (bill.customer !== this.originalBill.customer) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
printKot(guestBookId: string | null): Observable<boolean> {
|
||||
const item = JSON.parse(JSON.stringify(this.bill));
|
||||
const newKot = this.bill.kots.find((k) => k.id === undefined) as Kot;
|
||||
if (newKot.inventories.filter((x) => x.quantity !== 0).length === 0) {
|
||||
return throwError('Cannot print a blank KOT\nPlease add some products!');
|
||||
if (!this.isBillDiffent(item, guestBookId)) {
|
||||
return throwError(() => Error('Cannot print a blank KOT\nPlease add some products!'));
|
||||
}
|
||||
if (!this.happyHourItemsBalanced() || this.happyHourItemsMoreThanRegular()) {
|
||||
return throwError('Happy hour products are not balanced.');
|
||||
return throwError(() => Error('Happy hour products are not balanced.'));
|
||||
}
|
||||
return this.ser
|
||||
.saveOrUpdate(item, VoucherType.Kot, guestBookId, this.updateTable)
|
||||
.pipe(tap(() => (this.allowDeactivate = true)));
|
||||
}
|
||||
|
||||
printBill(guest_book_id: string | null, voucherType: VoucherType): Observable<boolean> {
|
||||
printBill(guestBookId: string | null, voucherType: VoucherType): Observable<boolean> {
|
||||
const item = JSON.parse(JSON.stringify(this.bill));
|
||||
const newKot = this.bill.kots.find((k) => k.id === undefined) as Kot;
|
||||
if (item.kots.length === 1 && newKot.inventories.length === 0) {
|
||||
return throwError('Cannot print a blank Bill\nPlease add some products!');
|
||||
const products = item.kots.reduce(
|
||||
(p: number, k: Kot) => p + k.inventories.filter((i) => i.quantity !== 0).length,
|
||||
0,
|
||||
);
|
||||
if (products === 0) {
|
||||
return throwError(() => Error('Cannot print a blank Bill\nPlease add some products!'));
|
||||
}
|
||||
if (!this.happyHourItemsBalanced() || this.happyHourItemsMoreThanRegular()) {
|
||||
return throwError('Happy hour products are not balanced.');
|
||||
return throwError(() => Error('Happy hour products are not balanced.'));
|
||||
}
|
||||
return this.ser
|
||||
.saveOrUpdate(item, voucherType, guest_book_id, this.updateTable)
|
||||
.saveOrUpdate(item, voucherType, guestBookId, this.updateTable)
|
||||
.pipe(tap(() => (this.allowDeactivate = true)));
|
||||
}
|
||||
|
||||
@ -364,6 +387,8 @@ export class BillService {
|
||||
}
|
||||
|
||||
private happyHourItemsMoreThanRegular(): boolean {
|
||||
// This is for the whole bill. eg. Kot 1 => Reg 2 + HH 2; Kot 2 => Reg 4; Kot 3 => Reg - 4
|
||||
// This is pass okay in happy hours items balanced, but overall this is wrong. Hence this check
|
||||
const invs: { [id: string]: { normal: number; happy: number } } = {};
|
||||
for (const kot of this.bill.kots) {
|
||||
for (const inventory of kot.inventories) {
|
||||
|
||||
@ -18,7 +18,7 @@ export class Bill {
|
||||
kotId: string;
|
||||
billId: string;
|
||||
table: Table;
|
||||
customer?: { id: string; name: string };
|
||||
customer: { id: string; name: string } | null;
|
||||
guest: GuestBook;
|
||||
reason: string;
|
||||
voucherType: VoucherType;
|
||||
@ -37,6 +37,7 @@ export class Bill {
|
||||
this.billId = '';
|
||||
this.kotId = '';
|
||||
this.table = new Table();
|
||||
this.customer = null;
|
||||
this.guest = new GuestBook();
|
||||
// this.settlements = [];
|
||||
this.reason = '';
|
||||
|
||||
@ -83,9 +83,10 @@ export class BillsComponent implements OnInit {
|
||||
|
||||
dialogRef.afterClosed().subscribe((result: boolean | Customer) => {
|
||||
if (!result) {
|
||||
return;
|
||||
this.bs.bill.customer = null;
|
||||
} else {
|
||||
this.bs.bill.customer = result as Customer;
|
||||
}
|
||||
this.bs.bill.customer = result as Customer;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user