From 67c3ead7ec3003dc6088ec250730e1d76e584cc0 Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Wed, 24 Jul 2024 09:26:17 +0700 Subject: [PATCH] fix: calculation --- src/controllers/quotation-controller.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/controllers/quotation-controller.ts b/src/controllers/quotation-controller.ts index 628d259..90f8a11 100644 --- a/src/controllers/quotation-controller.ts +++ b/src/controllers/quotation-controller.ts @@ -340,7 +340,7 @@ export class QuotationController extends Controller { const currentWork = currentService.work.find((d) => d.id === c.id); - if (!currentWork) return []; // should not possible + if (!currentWork) return []; // additional will get stripped return { id: currentWork.id, @@ -352,11 +352,13 @@ export class QuotationController extends Controller { if (!currentProduct) return []; // should not possible - price.totalPrice += currentProduct.price; - price.totalDiscount += Math.round(currentProduct.price * e.discount * 100) / 100; + price.totalPrice += currentProduct.price * e.amount; + price.totalDiscount += + Math.round(currentProduct.price * e.amount * e.discount * 100) / 100; price.totalVat += Math.round( - (currentProduct.price - currentProduct.price * e.discount) * + (currentProduct.price * e.amount - + currentProduct.price * e.amount * e.discount) * (e.vat === undefined ? 0.07 : e.vat) * 100, ) / 100; @@ -373,9 +375,6 @@ export class QuotationController extends Controller { }); const quotation = await tx.quotation.create({ - include: { - service: true, - }, data: { ...rest, statusOrder: +(rest.status === "INACTIVE"),