diff --git a/barker/barker/routers/reports/bill_settlement_report.py b/barker/barker/routers/reports/bill_settlement_report.py index b8f2c9d..4bcc21a 100644 --- a/barker/barker/routers/reports/bill_settlement_report.py +++ b/barker/barker/routers/reports/bill_settlement_report.py @@ -74,8 +74,6 @@ def settlements(s: date, f: date, db: Session) -> List[BillSettlementItem]: amount=round(so.amount, 2), ) ) - for i in report: - print(i.json()) return report diff --git a/bookie/src/app/sales/bill.service.ts b/bookie/src/app/sales/bill.service.ts index 4bca8ce..893dadd 100644 --- a/bookie/src/app/sales/bill.service.ts +++ b/bookie/src/app/sales/bill.service.ts @@ -34,6 +34,7 @@ export class BillService { public selection = new SelectionModel(true, []); private amountBs: BehaviorSubject; private updateTable: boolean; + private allowDeactivate: boolean; // To disable Deactivate Guard on navigation after printing bill or kot. constructor( private dialog: MatDialog, @@ -49,17 +50,19 @@ export class BillService { this.amountBs = new BehaviorSubject(0); this.amountVal = 0; this.updateTable = true; + this.allowDeactivate = false; this.amount = this.amountBs.pipe(tap((x) => (this.amountVal = x))); } displayBill(): void { + this.allowDeactivate = false; const data = this.transformBillToView(this.bill); this.dataObs.next(data); this.updateAmounts(); } transformBillToView(bill: Bill): BillViewItem[] { - const view: BillViewItem[] = bill.kots + return bill.kots .map((k: Kot) => [ new BillViewItem({ kotId: k.id, @@ -85,7 +88,6 @@ export class BillService { ), ]) .reduce((a, c) => a.concat(c), []); - return view; } loadData(bill: Bill, updateTable: boolean): void { @@ -241,7 +243,9 @@ export class BillService { if (!this.happyHourItemsBalanced() || this.happyHourItemsMoreThanRegular()) { return throwError('Happy hour products are not balanced.'); } - return this.ser.saveOrUpdate(item, VoucherType.Kot, guestBookId, this.updateTable); + return this.ser + .saveOrUpdate(item, VoucherType.Kot, guestBookId, this.updateTable) + .pipe(tap(() => (this.allowDeactivate = true))); } printBill(guest_book_id: string | null, voucherType: VoucherType): Observable { @@ -253,7 +257,9 @@ export class BillService { if (!this.happyHourItemsBalanced() || this.happyHourItemsMoreThanRegular()) { return throwError('Happy hour products are not balanced.'); } - return this.ser.saveOrUpdate(item, voucherType, guest_book_id, this.updateTable); + return this.ser + .saveOrUpdate(item, voucherType, guest_book_id, this.updateTable) + .pipe(tap(() => (this.allowDeactivate = true))); } receivePayment(value: { choices: ReceivePaymentItem[]; reason: string }): Observable { @@ -397,8 +403,11 @@ export class BillService { return false; } - public isDirty(): boolean { + public canDeactivate(): boolean { + if (this.allowDeactivate) { + return true; + } const newKot = this.bill.kots.find((k) => k.id === undefined) as Kot; - return newKot.inventories.length !== 0; + return newKot.inventories.length === 0; } } diff --git a/bookie/src/app/sales/can-deactivate-bill.guard.ts b/bookie/src/app/sales/can-deactivate-bill.guard.ts index 6a08300..aa3d53e 100644 --- a/bookie/src/app/sales/can-deactivate-bill.guard.ts +++ b/bookie/src/app/sales/can-deactivate-bill.guard.ts @@ -14,7 +14,7 @@ import { BillsComponent } from './bills/bills.component'; export class CanDeactivateBillGuard implements CanDeactivate { constructor(private dialog: MatDialog) {} canDeactivate(component: BillsComponent): Observable | boolean { - if (!component.bs.isDirty()) { + if (component.bs.canDeactivate()) { return observableOf(true); } const dialogRef = this.dialog.open(ConfirmDialogComponent, {