From bb0d14ce92459bb921acb6743624ff27140f941e Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Thu, 23 Jan 2025 10:21:10 +0700 Subject: [PATCH] fix: .01 wrong price --- src/controllers/05-quotation-controller.ts | 29 +++++++++++++--------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/controllers/05-quotation-controller.ts b/src/controllers/05-quotation-controller.ts index be18cc8..866b93a 100644 --- a/src/controllers/05-quotation-controller.ts +++ b/src/controllers/05-quotation-controller.ts @@ -477,13 +477,15 @@ export class QuotationController extends Controller { const list = body.productServiceList.map((v, i) => { const p = product.find((p) => p.id === v.productId)!; - const price = body.agentPrice ? p.agentPrice : p.price; + + const originalPrice = body.agentPrice ? p.agentPrice : p.price; + const finalPriceWithVat = precisionRound( + originalPrice + (p.vatIncluded ? 0 : originalPrice * 1.07), + ); + + const price = finalPriceWithVat; const pricePerUnit = p.vatIncluded ? price / (1 + VAT_DEFAULT) : price; - const vat = p.calcVat - ? (pricePerUnit * (v.discount ? v.amount : 1) - (v.discount || 0)) * - VAT_DEFAULT * - (!v.discount ? v.amount : 1) - : 0; + const vat = p.calcVat ? (pricePerUnit * v.amount - (v.discount || 0)) * VAT_DEFAULT : 0; return { order: i + 1, @@ -742,13 +744,16 @@ export class QuotationController extends Controller { const list = body.productServiceList?.map((v, i) => { const p = product.find((p) => p.id === v.productId)!; - const price = record.agentPrice ? p.agentPrice : p.price; + + const originalPrice = record.agentPrice ? p.agentPrice : p.price; + const finalPriceWithVat = precisionRound( + originalPrice + (p.vatIncluded ? 0 : originalPrice * 1.07), + ); + + const price = finalPriceWithVat; const pricePerUnit = p.vatIncluded ? price / (1 + VAT_DEFAULT) : price; - const vat = p.calcVat - ? (pricePerUnit * (v.discount ? v.amount : 1) - (v.discount || 0)) * - VAT_DEFAULT * - (!v.discount ? v.amount : 1) - : 0; + const vat = p.calcVat ? (pricePerUnit * v.amount - (v.discount || 0)) * VAT_DEFAULT : 0; + return { order: i + 1, productId: v.productId,