From ae8844087040bfe150401d35dc93dcc58fef4f83 Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Thu, 30 Jan 2025 14:26:45 +0700 Subject: [PATCH] refactor: use price in quotation instead --- src/pages/11_credit-note/FormPage.vue | 36 +++------- .../expansion/ProductExpansion.vue | 67 ++++++------------- 2 files changed, 31 insertions(+), 72 deletions(-) diff --git a/src/pages/11_credit-note/FormPage.vue b/src/pages/11_credit-note/FormPage.vue index f773e361..c0485725 100644 --- a/src/pages/11_credit-note/FormPage.vue +++ b/src/pages/11_credit-note/FormPage.vue @@ -111,7 +111,7 @@ const formTaskList = ref< let taskListGroup = computed(() => { const cacheData = formTaskList.value.reduce< { - product: RequestWork['productService']['product']; + product: RequestWork['productService']; list: RequestWork[]; }[] >((acc, curr) => { @@ -129,7 +129,7 @@ let taskListGroup = computed(() => { exist.list.push(task.requestWork); } else { acc.push({ - product: task.requestWork.productService.product, + product: task.requestWork.productService, list: [record], }); } @@ -189,42 +189,28 @@ async function initStatus() { function getPrice( list: { - product: RequestWork['productService']['product']; + product: RequestWork['productService']; list: RequestWork[]; }[], ) { return list.reduce( (a, c) => { - const agentPrice = !!quotationData.value?.agentPrice; - const pricePerUnit = agentPrice ? c.product.agentPrice : c.product.price; + const pricePerUnit = + c.product.pricePerUnit - c.product.discount / c.product.amount; const amount = c.list.length; - const discount = 0; - const priceNoVat = c.product[ - agentPrice ? 'agentPriceVatIncluded' : 'vatIncluded' - ] - ? pricePerUnit / (1 + (config.value?.vat || 0.07)) - : pricePerUnit; - const priceDiscountNoVat = priceNoVat * amount - discount; + const priceNoVat = pricePerUnit; + const priceDiscountNoVat = priceNoVat * amount; const rawVatTotal = priceDiscountNoVat * (config.value?.vat || 0.07); - // const rawVat = rawVatTotal / amount; a.totalPrice = a.totalPrice + priceDiscountNoVat; - a.totalDiscount = a.totalDiscount + Number(discount); - a.vat = c.product[agentPrice ? 'agentPriceCalcVat' : 'calcVat'] - ? a.vat + rawVatTotal - : a.vat; - a.vatExcluded = c.product[agentPrice ? 'agentPriceCalcVat' : 'calcVat'] - ? a.vatExcluded - : a.vat + rawVatTotal; - a.finalPrice = a.totalPrice - a.totalDiscount + a.vat; + a.vat = c.product.vat !== 0 ? a.vat + rawVatTotal : a.vat; + a.finalPrice = a.totalPrice + a.vat; return a; }, { totalPrice: 0, - totalDiscount: 0, vat: 0, - vatExcluded: 0, finalPrice: 0, }, ); @@ -754,12 +740,12 @@ onMounted(async () => { " /> -