mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-29 02:30:55 +00:00
feat: implement first and last mile trucking pricing logic in booking and contract services
This commit is contained in:
@@ -123,12 +123,43 @@ export class ContractPricingService {
|
||||
}
|
||||
}
|
||||
|
||||
// Conditional surcharges — shown only when the contract toggles them on.
|
||||
// First / last mile trucking unit rates — shown when the contract carries
|
||||
// that leg. Per-unit prices only; the actual amount (× km / containers /
|
||||
// tons / flat) is computed at booking time.
|
||||
if (contract.firstMilePickupAddress) {
|
||||
const fm = liveRates.find(
|
||||
(r) => r.rateType === 'FIRST_MILE' && r.currency === 'USD',
|
||||
);
|
||||
if (fm && Number(fm.rateValue) > 0) {
|
||||
lineItems.push({
|
||||
code: 'FIRST_MILE',
|
||||
label: 'First mile (pick-up)',
|
||||
unit: toContractUnit(fm.rateUnit),
|
||||
unitPrice: convert(Number(fm.rateValue)),
|
||||
});
|
||||
}
|
||||
}
|
||||
if (contract.lastMileDeliveryAddress) {
|
||||
const lm = liveRates.find(
|
||||
(r) => r.rateType === 'LAST_MILE' && r.currency === 'USD',
|
||||
);
|
||||
if (lm && Number(lm.rateValue) > 0) {
|
||||
lineItems.push({
|
||||
code: 'LAST_MILE',
|
||||
label: 'Last mile (delivery)',
|
||||
unit: toContractUnit(lm.rateUnit),
|
||||
unitPrice: convert(Number(lm.rateValue)),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Conditional surcharges — shown only when the contract toggles them on AND
|
||||
// the rate has a non-zero value (a 0 rate means "no surcharge").
|
||||
if (contract.isHazardous) {
|
||||
const hazard = liveRates.find(
|
||||
(r) => r.rateType === 'HAZARD_SURCHARGE' && r.currency === 'USD',
|
||||
);
|
||||
if (hazard) {
|
||||
if (hazard && Number(hazard.rateValue) > 0) {
|
||||
lineItems.push({
|
||||
code: 'HAZARD_SURCHARGE',
|
||||
label: 'Hazardous surcharge',
|
||||
@@ -142,7 +173,7 @@ export class ContractPricingService {
|
||||
const reefer = liveRates.find(
|
||||
(r) => r.rateType === 'REEFER_SURCHARGE' && r.currency === 'USD',
|
||||
);
|
||||
if (reefer) {
|
||||
if (reefer && Number(reefer.rateValue) > 0) {
|
||||
lineItems.push({
|
||||
code: 'REEFER_SURCHARGE',
|
||||
label: 'Reefer surcharge',
|
||||
|
||||
Reference in New Issue
Block a user