From d70c686cc8e38ab4c2dd0602cfb6ee2184aa2dfc Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Thu, 11 Sep 2025 13:43:35 +0700 Subject: [PATCH] fix: price calc --- src/components/05_quotation/ProductItem.vue | 40 ++++++---- src/pages/05_quotation/QuotationForm.vue | 31 +++----- src/pages/05_quotation/QuotationFormInfo.vue | 4 +- src/pages/05_quotation/preview/ViewForm.vue | 77 ++++++-------------- 4 files changed, 63 insertions(+), 89 deletions(-) diff --git a/src/components/05_quotation/ProductItem.vue b/src/components/05_quotation/ProductItem.vue index b1996d03..cfa2ad8e 100644 --- a/src/components/05_quotation/ProductItem.vue +++ b/src/components/05_quotation/ProductItem.vue @@ -58,16 +58,15 @@ const currentBtnOpen = ref<{ title: string; opened: boolean[] }[]>([ function calcPrice(c: (typeof rows.value)[number]) { const originalPrice = c.pricePerUnit; - const finalPriceWithVat = precisionRound( - originalPrice + originalPrice * (config.value?.vat || 0.07), + const finalPricePerUnit = precisionRound( + originalPrice + + (c.product[props.agentPrice ? 'agentPriceCalcVat' : 'calcVat'] + ? originalPrice * (config.value?.vat || 0.07) + : 0), ); - const finalPriceNoVat = finalPriceWithVat / (1 + (config.value?.vat || 0.07)); + const price = finalPricePerUnit * c.amount - c.discount; - const price = finalPriceNoVat * c.amount - c.discount; - const vat = c.product[props.agentPrice ? 'agentPriceCalcVat' : 'calcVat'] - ? (finalPriceNoVat * c.amount - c.discount) * (config.value?.vat || 0.07) - : 0; - return precisionRound(price + vat); + return precisionRound(price); } const discount4Show = ref([]); @@ -435,8 +434,20 @@ watch( {{ formatNumberDecimal( - props.row.pricePerUnit * props.row.amount - - props.row.discount, + props.row.product[ + agentPrice ? 'agentPriceCalcVat' : 'calcVat' + ] + ? precisionRound( + (props.row.pricePerUnit * + (1 + (config?.vat || 0.07)) * + props.row.amount - + props.row.discount) / + (1 + (config?.vat || 0.07)), + ) + : precisionRound( + props.row.pricePerUnit * props.row.amount - + props.row.discount, + ), 2, ) }} @@ -448,9 +459,12 @@ watch( agentPrice ? 'agentPriceCalcVat' : 'calcVat' ] ? precisionRound( - (props.row.pricePerUnit * props.row.amount - - props.row.discount) * - (config?.vat || 0.07), + ((props.row.pricePerUnit * + (1 + (config?.vat || 0.07)) * + props.row.amount - + props.row.discount) / + (1 + (config?.vat || 0.07))) * + 0.07, ) : 0, 2, diff --git a/src/pages/05_quotation/QuotationForm.vue b/src/pages/05_quotation/QuotationForm.vue index dd5b5aeb..e46f911f 100644 --- a/src/pages/05_quotation/QuotationForm.vue +++ b/src/pages/05_quotation/QuotationForm.vue @@ -248,32 +248,23 @@ function getPrice( return a; } - const originalPrice = c.pricePerUnit; - const finalPriceWithVat = precisionRound( - originalPrice * (1 + (config.value?.vat || 0.07)), - ); - const finalPriceNoVat = - finalPriceWithVat / (1 + (config.value?.vat || 0.07)); - - const price = finalPriceNoVat * c.amount; - const vat = - (finalPriceNoVat * c.amount - c.discount) * (config.value?.vat || 0.07); - const calcVat = c.product[agentPrice.value ? 'agentPriceCalcVat' : 'calcVat']; + const vatFactor = calcVat ? (config.value?.vat ?? 0.07) : 0; - a.totalPrice = precisionRound(a.totalPrice + price); - a.totalDiscount = precisionRound(a.totalDiscount + Number(c.discount)); - a.vat = calcVat ? precisionRound(a.vat + vat) : a.vat; + const price = precisionRound( + (c.pricePerUnit * c.amount * (1 + vatFactor) - c.discount) / + (1 + vatFactor), + ); + const vat = price * vatFactor; + + a.totalPrice = precisionRound(a.totalPrice + price + c.discount); + a.totalDiscount = precisionRound(a.totalDiscount + c.discount); + a.vat = precisionRound(a.vat + vat); a.vatExcluded = calcVat ? a.vatExcluded : precisionRound(a.vatExcluded + price); - a.finalPrice = precisionRound( - a.totalPrice - - a.totalDiscount + - a.vat - - Number(quotationFormData.value.discount || 0), - ); + a.finalPrice = precisionRound(a.totalPrice - a.totalDiscount + a.vat); return a; }, diff --git a/src/pages/05_quotation/QuotationFormInfo.vue b/src/pages/05_quotation/QuotationFormInfo.vue index 5f9f45b3..c0324392 100644 --- a/src/pages/05_quotation/QuotationFormInfo.vue +++ b/src/pages/05_quotation/QuotationFormInfo.vue @@ -446,7 +446,9 @@ watch( {{ formatNumberDecimal( - summaryPrice.totalPrice - summaryPrice.totalDiscount, + summaryPrice.totalPrice - + summaryPrice.totalDiscount - + summaryPrice.vatExcluded, 2, ) }} diff --git a/src/pages/05_quotation/preview/ViewForm.vue b/src/pages/05_quotation/preview/ViewForm.vue index 9977a6c7..4f6d1904 100644 --- a/src/pages/05_quotation/preview/ViewForm.vue +++ b/src/pages/05_quotation/preview/ViewForm.vue @@ -1,6 +1,6 @@