mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-27 00:52:50 +00:00
Merge pull request #439 from Tria-plc/freight/feature/first_mile_invoice
Freight/feature/first mile invoice
This commit is contained in:
@@ -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.`,
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user