From e0d24b49cbe786d03d9bbfc24a06f74407799823 Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Tue, 10 Dec 2024 17:04:59 +0700 Subject: [PATCH] fix: price not match with original price by .01 This will calculate quantity later when no discount is set. However when discount is set there may be some number that can introduce +-0.01 --- src/components/05_quotation/ProductItem.vue | 10 +++++++--- src/pages/05_quotation/QuotationForm.vue | 8 +++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/components/05_quotation/ProductItem.vue b/src/components/05_quotation/ProductItem.vue index 6ef1544e..a8306058 100644 --- a/src/components/05_quotation/ProductItem.vue +++ b/src/components/05_quotation/ProductItem.vue @@ -54,9 +54,13 @@ function calcPrice(c: (typeof rows.value)[number]) { return precisionRound( c.pricePerUnit * c.amount - c.discount + - (c.product.calcVat - ? (c.pricePerUnit * c.amount - c.discount) * (config.value?.vat || 0.07) - : 0), + precisionRound( + c.product.calcVat + ? (c.pricePerUnit * (c.discount ? c.amount : 1) - c.discount) * + (config.value?.vat || 0.07) + : 0, + ) * + (!c.discount ? c.amount : 1), ); } diff --git a/src/pages/05_quotation/QuotationForm.vue b/src/pages/05_quotation/QuotationForm.vue index 0002ee10..a2155f36 100644 --- a/src/pages/05_quotation/QuotationForm.vue +++ b/src/pages/05_quotation/QuotationForm.vue @@ -214,9 +214,11 @@ function getPrice( } const price = precisionRound(c.pricePerUnit * c.amount); - const vat = precisionRound( - (c.pricePerUnit * c.amount - c.discount) * (config.value?.vat || 0.07), - ); + const vat = + precisionRound( + (c.pricePerUnit * (c.discount ? c.amount : 1) - c.discount) * + (config.value?.vat || 0.07), + ) * (!c.discount ? c.amount : 1); a.totalPrice = precisionRound(a.totalPrice + price); a.totalDiscount = precisionRound(a.totalDiscount + Number(c.discount));