feat: price summary

This commit is contained in:
Methapon Metanipat 2024-10-10 09:24:02 +07:00
parent 47272f46de
commit b292e00380
4 changed files with 85 additions and 32 deletions

View file

@ -48,6 +48,8 @@ const groupList = ref<
}[]
>([]);
const finalDiscount = defineModel<number>('finalDiscount', { default: 0 });
const summaryPrice = defineModel<{
totalPrice: number;
totalDiscount: number;
@ -66,14 +68,13 @@ const summaryPrice = defineModel<{
const currentBtnOpen = ref<{ title: string; opened: boolean[] }[]>([
{ title: '', opened: [] },
]);
const finalDiscount = ref<number>(0);
const finalDiscount4Show = ref<string>(finalDiscount.value.toString());
function calcPrice(c: (typeof rows.value)[number]) {
return precisionRound(
c.pricePerUnit * c.amount -
c.discount +
c.pricePerUnit * (config.value?.vat || 0.07) * c.amount,
(c.pricePerUnit * c.amount - c.discount) * (config.value?.vat || 0.07),
);
}
@ -88,7 +89,9 @@ const summary = computed(() =>
a.totalPrice = precisionRound(a.totalPrice + price);
a.totalDiscount = precisionRound(a.totalDiscount + Number(c.discount));
a.vat = precisionRound(a.vat + vat);
a.finalPrice = precisionRound(a.finalPrice + price + vat);
a.finalPrice = precisionRound(
a.totalPrice - a.totalDiscount + a.vat - Number(finalDiscount.value),
);
return a;
},
@ -96,7 +99,7 @@ const summary = computed(() =>
totalPrice: 0,
totalDiscount: 0,
vat: 0,
finalPrice: -(+finalDiscount.value || 0),
finalPrice: 0,
},
),
);