From 2c90c0c1435b62fb068c12308cfa431f3125bbff Mon Sep 17 00:00:00 2001 From: Methapon Metanipat Date: Fri, 18 Oct 2024 14:49:10 +0700 Subject: [PATCH] fix: empty payment data on full payment --- src/controllers/05-quotation-controller.ts | 42 ++++++++++++---------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/src/controllers/05-quotation-controller.ts b/src/controllers/05-quotation-controller.ts index e5e18d5..9af1573 100644 --- a/src/controllers/05-quotation-controller.ts +++ b/src/controllers/05-quotation-controller.ts @@ -466,15 +466,18 @@ export class QuotationController extends Controller { ...rest, ...price, quotationPaymentData: { - create: rest.paySplit?.map((v) => ({ - paymentStatus: "PaymentWait", - amount: v.amount, - date: v.date, - })) || { - paymentStatus: "PaymentWait", - amount: price.finalPrice, - date: new Date(), - }, + create: + rest.payCondition === "BillSplit" || rest.payCondition === "Split" + ? rest.paySplit?.map((v) => ({ + paymentStatus: "PaymentWait", + amount: v.amount, + date: v.date, + })) + : { + paymentStatus: "PaymentWait", + amount: price.finalPrice, + date: new Date(), + }, }, statusOrder: +(rest.status === "INACTIVE"), code: `${currentYear.toString().padStart(2, "0")}${currentMonth.toString().padStart(2, "0")}${currentDate.toString().padStart(2, "0")}${lastQuotation.value.toString().padStart(4, "0")}`, @@ -721,15 +724,18 @@ export class QuotationController extends Controller { price && record.quotationStatus === "PaymentPending" ? { deleteMany: {}, - create: rest.paySplit?.map((v) => ({ - paymentStatus: "PaymentWait", - amount: v.amount, - date: v.date, - })) || { - paymentStatus: "PaymentWait", - amount: price.finalPrice, - date: new Date(), - }, + create: + rest.payCondition === "BillSplit" || rest.payCondition === "Split" + ? rest.paySplit?.map((v) => ({ + paymentStatus: "PaymentWait", + amount: v.amount, + date: v.date, + })) + : { + paymentStatus: "PaymentWait", + amount: price.finalPrice, + date: new Date(), + }, } : undefined, statusOrder: +(rest.status === "INACTIVE"),