This commit is contained in:
natib21
2026-07-04 00:37:36 +00:00
parent 4994d14002
commit 6bf7371716
2 changed files with 14 additions and 4 deletions

View File

@@ -57,7 +57,8 @@ export class FirstMileInvoiceService {
return null;
}
const totalAmount = record.remainingPayment || 0;
// numeric columns come back as strings — coerce before the finite/>0 check.
const totalAmount = Number(record.remainingPayment) || 0;
if (!Number.isFinite(totalAmount) || totalAmount <= 0) {
this.logger.warn(
`Skipping invoice for first-mile record ${record.id}: no remaining payment.`,

View File

@@ -54,6 +54,15 @@ export class LastMileInvoiceService {
return null;
}
// numeric columns come back as strings — coerce before billing.
const totalAmount = Number(record.remainingPayment) || 0;
if (!Number.isFinite(totalAmount) || totalAmount <= 0) {
this.logger.warn(
`Skipping invoice for last-mile record ${record.id}: no remaining payment.`,
);
return null;
}
// Generate invoice with remainingPayment as totalAmount
const input: GenerateInvoiceInput = {
source: 'last_mile' as Freight.InvoiceSource,
@@ -67,11 +76,11 @@ export class LastMileInvoiceService {
chargeType: 'DELIVERY',
description: 'Last-mile delivery',
quantity: 1,
unitRate: record.remainingPayment || 0,
amount: record.remainingPayment || 0,
unitRate: totalAmount,
amount: totalAmount,
},
],
totalAmount: record.remainingPayment || 0,
totalAmount,
};
return this.billing.generateInvoice(input);