diff --git a/src/controllers/05-payment-controller.ts b/src/controllers/05-payment-controller.ts index 9f73b75..c000278 100644 --- a/src/controllers/05-payment-controller.ts +++ b/src/controllers/05-payment-controller.ts @@ -156,7 +156,7 @@ export class QuotationPayment extends Controller { }, }); - const paymentSum = await prisma.payment.aggregate({ + const paymentSum = await tx.payment.aggregate({ _sum: { amount: true }, where: { invoice: { @@ -166,10 +166,6 @@ export class QuotationPayment extends Controller { }, }); - if (body.paymentStatus === "PaymentSuccess") { - paymentSum._sum.amount = (paymentSum._sum.amount || 0) + payment.amount; - } - await tx.quotation.update({ where: { id: quotation.id }, data: { @@ -178,7 +174,8 @@ export class QuotationPayment extends Controller { ? "PaymentSuccess" : "PaymentInProcess", requestData: - quotation.quotationStatus === "PaymentPending" + body.paymentStatus === "PaymentSuccess" && + (paymentSum._sum.amount || 0) - payment.amount <= 0 ? { create: quotation.worker.map((v) => ({ employeeId: v.employeeId,