fix: wrong condition

This commit is contained in:
Methapon Metanipat 2024-11-14 11:54:26 +07:00
parent 0410c56060
commit 82fd331205

View file

@ -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,