From 2c99b92aa5ca1308d2e483d5f1dbec4f5872c32f Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Wed, 24 Jul 2024 14:26:06 +0700 Subject: [PATCH] fix: error and price calc --- src/controllers/quotation-controller.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/controllers/quotation-controller.ts b/src/controllers/quotation-controller.ts index bf3a88a..6e77fa9 100644 --- a/src/controllers/quotation-controller.ts +++ b/src/controllers/quotation-controller.ts @@ -96,7 +96,7 @@ type QuotationUpdate = { payBillDate?: Date; - workerCount: number; + workerCount?: number; // EmployeeId or Create new employee worker?: ( | string @@ -503,10 +503,10 @@ export class QuotationController extends Controller { const [customer, customerBranch, employee, service, product] = await prisma.$transaction( async (tx) => await Promise.all([ - tx.customer.findUnique({ + tx.customer.findFirst({ where: { id: body.customerId }, }), - tx.customerBranch.findUnique({ + tx.customerBranch.findFirst({ include: { customer: true }, where: { id: body.customerBranchId }, }), @@ -638,11 +638,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; @@ -704,7 +706,7 @@ export class QuotationController extends Controller { }, }); - if (restructureService) + if (restructureService) { await Promise.all( restructureService.map(async (a) => { const { id: _currentServiceId } = await tx.quotationService.create({ @@ -744,6 +746,7 @@ export class QuotationController extends Controller { ); }), ); + } return await tx.quotation.findUnique({ include: {