diff --git a/src/pages/05_quotation/QuotationForm.vue b/src/pages/05_quotation/QuotationForm.vue index f65b3724..e7f2f70b 100644 --- a/src/pages/05_quotation/QuotationForm.vue +++ b/src/pages/05_quotation/QuotationForm.vue @@ -252,10 +252,11 @@ function getPrice( c.product[agentPrice.value ? 'agentPriceCalcVat' : 'calcVat']; const vatFactor = calcVat ? (config.value?.vat ?? 0.07) : 0; - const price = precisionRound( - (c.pricePerUnit * c.amount * (1 + vatFactor) - c.discount) / - (1 + vatFactor), - ); + const pricePerUnit = + precisionRound(c.pricePerUnit * (1 + vatFactor)) / (1 + vatFactor); + const price = + (pricePerUnit * c.amount * (1 + vatFactor) - c.discount) / + (1 + vatFactor); const vat = price * vatFactor; a.totalPrice = precisionRound(a.totalPrice + price + c.discount); @@ -714,19 +715,16 @@ function handleUpdateProductTable( // handleChangePayType(quotationFormData.value.payCondition); // calc price const calc = (c: QuotationPayload['productServiceList'][number]) => { - const originalPrice = c.pricePerUnit || 0; - const finalPriceWithVat = precisionRound( - originalPrice * (1 + (config.value?.vat || 0.07)), - ); - const finalPriceNoVat = - finalPriceWithVat / (1 + (config.value?.vat || 0.07)); + const calcVat = + c.product[agentPrice.value ? 'agentPriceCalcVat' : 'calcVat']; + const vatFactor = calcVat ? (config.value?.vat ?? 0.07) : 0; + const pricePerUnit = + precisionRound(c.pricePerUnit * (1 + vatFactor)) / (1 + vatFactor); + const price = + (c.pricePerUnit * c.amount * (1 + vatFactor) - c.discount) / + (1 + vatFactor); - const price = finalPriceNoVat * c.amount; - const vat = c.product.calcVat - ? (finalPriceNoVat * c.amount - (c.discount || 0)) * - (config.value?.vat || 0.07) - : 0; - return precisionRound(price + vat); + return price; }; // installment @@ -779,21 +777,17 @@ function toggleDeleteProduct(index: number) { // cal curr amount if (currPaySplit && currTempPaySplit) { - const price = agentPrice.value - ? currProduct.product.agentPrice - : currProduct.product.price; - const pricePerUnit = currProduct.product.vatIncluded - ? price / (1 + (config.value?.vat || 0.07)) - : price; - const vat = - (pricePerUnit * currProduct.amount - currProduct.discount) * - (config.value?.vat || 0.07); - const finalPrice = - pricePerUnit * currProduct.amount + - vat - - Number(currProduct.discount || 0); + const calcVat = + currProduct.product[agentPrice.value ? 'agentPriceCalcVat' : 'calcVat']; + const vatFactor = calcVat ? (config.value?.vat ?? 0.07) : 0; - currTempPaySplit.amount = currPaySplit.amount - finalPrice; + const price = precisionRound( + (currProduct.pricePerUnit * currProduct.amount * (1 + vatFactor) - + currProduct.discount) / + (1 + vatFactor), + ); + + currTempPaySplit.amount = currPaySplit.amount - price; currPaySplit.amount = currTempPaySplit.amount; } @@ -848,8 +842,7 @@ function convertToTable(nodes: Node[]) { tempTableProduct.value = JSON.parse(JSON.stringify(list)); if (nodes.length > 0) { - quotationFormData.value.paySplit = Array.apply( - null, + quotationFormData.value.paySplit = Array.from( new Array(quotationFormData.value.paySplitCount), ).map((_, i) => ({ no: i + 1,