Fix: Edge cases where backend and frontend totals are off and you cannot settle the bill.

This commit is contained in:
2026-09-02 13:06:34 +00:00
parent 458dfaad50
commit 85ba7b326a
3 changed files with 67 additions and 29 deletions
+39 -8
View File
@@ -37,25 +37,36 @@ export class BillService {
public grossAmount = computed(() =>
this.math.halfRoundEven(
this.data().reduce((t, k) => k.inventories.reduce((a, c) => a + c.price * c.quantity, 0) + t, 0),
this.data().reduce(
(t, k) => k.inventories.filter((c) => !c.parentId).reduce((a, c) => a + c.price * c.quantity, 0) + t,
0,
),
2,
),
);
public hhAmount = computed(() =>
this.math.halfRoundEven(
this.data().reduce(
(t, k) => k.inventories.reduce((a, c) => a + (c.isHappyHour ? c.price : 0) * c.quantity, 0) + t,
(t, k) =>
k.inventories.filter((c) => !c.parentId).reduce((a, c) => a + (c.isHappyHour ? c.price : 0) * c.quantity, 0) +
t,
0,
),
2,
),
);
public discountAmount = computed(() =>
this.math.halfRoundEven(
this.data().reduce(
(t, k) => k.inventories.reduce((a, c) => a + (c.isHappyHour ? 0 : c.price) * c.quantity * c.discount, 0) + t,
(t, k) =>
k.inventories
.filter((c) => !c.parentId)
.reduce((a, c) => a + (c.isHappyHour ? 0 : c.price) * c.quantity * c.discount, 0) + t,
0,
),
2,
),
);
@@ -63,16 +74,36 @@ export class BillService {
this.math.halfRoundEven(
this.data().reduce(
(t, k) =>
k.inventories.reduce(
(a, c) => a + (c.isHappyHour ? 0 : c.price) * c.quantity * (1 - c.discount) * c.taxRate,
0,
) + t,
k.inventories
.filter((c) => !c.parentId)
.reduce((a, c) => a + (c.isHappyHour ? 0 : c.price) * c.quantity * (1 - c.discount) * c.taxRate, 0) + t,
0,
),
2,
),
);
public amount = computed(() =>
this.math.halfRoundEven(
this.data().reduce(
(t, k) =>
k.inventories
.filter((c) => !c.parentId)
.reduce(
(a, c) =>
a +
this.math.halfRoundEven(
(c.isHappyHour ? 0 : c.price) * c.quantity * (1 - c.discount) * (1 + c.taxRate),
2,
),
0,
) + t,
0,
),
0,
),
);
public amount = computed(() => this.grossAmount() - this.discountAmount() + this.taxAmount());
public selection = new SelectionModel<string>(true, []);
private updateTable = signal<boolean>(true);
private allowDeactivate = signal<boolean>(false);