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: {