Merge pull request #439 from Tria-plc/freight/feature/first_mile_invoice

Freight/feature/first mile invoice
This commit is contained in:
yaschalew10
2026-07-04 03:40:51 +03:00
committed by GitHub
2 changed files with 14 additions and 4 deletions

View File

@@ -57,7 +57,8 @@ export class FirstMileInvoiceService {
return null; 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) { if (!Number.isFinite(totalAmount) || totalAmount <= 0) {
this.logger.warn( this.logger.warn(
`Skipping invoice for first-mile record ${record.id}: no remaining payment.`, `Skipping invoice for first-mile record ${record.id}: no remaining payment.`,

View File

@@ -54,6 +54,15 @@ export class LastMileInvoiceService {
return null; 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 // Generate invoice with remainingPayment as totalAmount
const input: GenerateInvoiceInput = { const input: GenerateInvoiceInput = {
source: 'last_mile' as Freight.InvoiceSource, source: 'last_mile' as Freight.InvoiceSource,
@@ -67,11 +76,11 @@ export class LastMileInvoiceService {
chargeType: 'DELIVERY', chargeType: 'DELIVERY',
description: 'Last-mile delivery', description: 'Last-mile delivery',
quantity: 1, quantity: 1,
unitRate: record.remainingPayment || 0, unitRate: totalAmount,
amount: record.remainingPayment || 0, amount: totalAmount,
}, },
], ],
totalAmount: record.remainingPayment || 0, totalAmount,
}; };
return this.billing.generateInvoice(input); return this.billing.generateInvoice(input);