mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-30 05:18:11 +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;
|
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.`,
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
Reference in New Issue
Block a user