Chore: In overlord / sale / bill.service now the BillViewItem is just a view item
The data is kept as the original bill object and this view generated on every change. It has no sanctity. To deal with the challenges of Selection of items in the bill.component.html created a bill selection item. This is converted to string while checking else the selection model fails. Feature: It now checks if Happy Hour items have equivalent regular items in each kot. Feature: Discount won't apply to happy hour items. Checks for both are both in front end and back end.
This commit is contained in:
@ -16,7 +16,9 @@ import { QuantityComponent } from '../quantity/quantity.component';
|
||||
import { TablesDialogComponent } from '../tables-dialog/tables-dialog.component';
|
||||
|
||||
import { Bill } from './bill';
|
||||
import { BillSelectionItem } from './bill-selection-item';
|
||||
import { BillsDataSource } from './bills-datasource';
|
||||
import { Inventory } from './inventory';
|
||||
import { Kot } from './kot';
|
||||
import { VoucherType } from './voucher-type';
|
||||
|
||||
@ -66,33 +68,88 @@ export class BillsComponent implements OnInit {
|
||||
});
|
||||
}
|
||||
|
||||
isAllSelected(kot: Kot) {
|
||||
return this.bs.data
|
||||
.filter((x) => x.kotId === kot.id)
|
||||
.reduce((p: boolean, c: BillViewItem) => p && this.bs.selection.isSelected(c), true);
|
||||
isAllSelected(kotView: BillViewItem): boolean {
|
||||
const kot = this.bs.bill.kots.find((k) => k.id === kotView.kotId) as Kot;
|
||||
return kot.inventories.reduce(
|
||||
(p: boolean, c: Inventory) =>
|
||||
p &&
|
||||
this.bs.selection.isSelected(
|
||||
JSON.stringify(
|
||||
new BillSelectionItem({
|
||||
kotId: kot.id,
|
||||
inventoryId: c.id,
|
||||
productId: c.product.id,
|
||||
isHappyHour: c.isHappyHour,
|
||||
}),
|
||||
),
|
||||
),
|
||||
true,
|
||||
);
|
||||
}
|
||||
|
||||
isAnySelected(kot: Kot) {
|
||||
toggle(invView: BillViewItem) {
|
||||
const key = JSON.stringify(
|
||||
new BillSelectionItem({
|
||||
kotId: invView.kotId,
|
||||
inventoryId: invView.id,
|
||||
productId: invView.productId,
|
||||
isHappyHour: invView.isHappyHour,
|
||||
}),
|
||||
);
|
||||
this.bs.selection.toggle(key);
|
||||
}
|
||||
|
||||
isSelected(invView: BillViewItem): boolean {
|
||||
const key = JSON.stringify(
|
||||
new BillSelectionItem({
|
||||
kotId: invView.kotId,
|
||||
inventoryId: invView.id,
|
||||
productId: invView.productId,
|
||||
isHappyHour: invView.isHappyHour,
|
||||
}),
|
||||
);
|
||||
return this.bs.selection.isSelected(key);
|
||||
}
|
||||
|
||||
isAnySelected(kotView: BillViewItem) {
|
||||
const kot = this.bs.bill.kots.find((k) => k.id === kotView.kotId) as Kot;
|
||||
let total = 0;
|
||||
let found = 0;
|
||||
this.bs.data
|
||||
.filter((x) => x.kotId === kot.id)
|
||||
.forEach((c: BillViewItem) => {
|
||||
total += 1;
|
||||
if (this.bs.selection.isSelected(c)) {
|
||||
found += 1;
|
||||
}
|
||||
});
|
||||
for (const item of kot.inventories) {
|
||||
const key = JSON.stringify(
|
||||
new BillSelectionItem({
|
||||
kotId: kot.id,
|
||||
inventoryId: item.id,
|
||||
productId: item.product.id,
|
||||
isHappyHour: item.isHappyHour,
|
||||
}),
|
||||
);
|
||||
total += 1;
|
||||
if (this.bs.selection.isSelected(key)) {
|
||||
found += 1;
|
||||
}
|
||||
}
|
||||
return found > 0 && found < total;
|
||||
}
|
||||
|
||||
masterToggle(kot: Kot) {
|
||||
const isAllSelected = this.isAllSelected(kot);
|
||||
this.bs.data
|
||||
.filter((x) => x.kotId === kot.id)
|
||||
.forEach((row) =>
|
||||
isAllSelected ? this.bs.selection.deselect(row) : this.bs.selection.select(row),
|
||||
masterToggle(kotView: BillViewItem) {
|
||||
const isAllSelected = this.isAllSelected(kotView);
|
||||
const kot = this.bs.bill.kots.find((k) => k.id === kotView.kotId) as Kot;
|
||||
for (const item of kot.inventories) {
|
||||
const key = JSON.stringify(
|
||||
new BillSelectionItem({
|
||||
kotId: kot.id,
|
||||
inventoryId: item.id,
|
||||
productId: item.product.id,
|
||||
isHappyHour: item.isHappyHour,
|
||||
}),
|
||||
);
|
||||
if (isAllSelected) {
|
||||
this.bs.selection.deselect(key);
|
||||
} else {
|
||||
this.bs.selection.select(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
addOne(item: BillViewItem): void {
|
||||
@ -109,18 +166,7 @@ export class BillsComponent implements OnInit {
|
||||
if (!result) {
|
||||
return;
|
||||
}
|
||||
if (!item.isPrinted) {
|
||||
this.bs.quantity(item, result as number);
|
||||
} else {
|
||||
const quantity = result as number;
|
||||
const product = {
|
||||
...item.product,
|
||||
hasHappyHour: item.isHappyHour,
|
||||
tax: item.tax,
|
||||
price: item.price,
|
||||
};
|
||||
this.bs.addProduct(product, quantity, item.discount);
|
||||
}
|
||||
this.bs.quantity(item, result as number);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user