mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-28 23:00:57 +00:00
Merge pull request #807 from Tria-plc/freight_feature/usermanagement
add contract clearance detail page and enhance contract requests fil…
This commit is contained in:
@@ -596,11 +596,40 @@ export class ContractBookingService {
|
||||
if (!booking || booking.contractId !== contract.id) {
|
||||
throw new NotFoundException(`Booking ${bookingId} not found on this contract`);
|
||||
}
|
||||
if (!['CLEARANCE_READY', 'OPERATION_CHANGES_REQUESTED'].includes(booking.status)) {
|
||||
if (
|
||||
!['CLEARANCE_READY', 'OPERATION_CHANGES_REQUESTED', 'EXPIRED'].includes(
|
||||
booking.status,
|
||||
)
|
||||
) {
|
||||
throw new BadRequestException(
|
||||
'Clearance must be finalized before the booking can be completed.',
|
||||
);
|
||||
}
|
||||
// An unpaid booking that expired at train dispatch keeps its finished
|
||||
// per-booking clearance — GL rebooks it onto a new shipment day instead of
|
||||
// forcing the customer through a new shipment request + clearance fee.
|
||||
if (booking.status === 'EXPIRED') {
|
||||
// Only a booking that completed once (it has a price, so its clearance
|
||||
// finished and cargo is persisted) can be rebooked after expiry.
|
||||
if (!(Number(booking.totalAmount) > 0)) {
|
||||
throw new BadRequestException(
|
||||
'Only a previously completed booking can be rebooked after it expires.',
|
||||
);
|
||||
}
|
||||
// Expiry released the booking's contract-capacity hold; if the payload
|
||||
// re-states the cargo, make sure the released share is still free.
|
||||
if (dto.containers?.length || dto.bulkLines?.length) {
|
||||
await this.assertWithinQuantityCap(contract, dto);
|
||||
}
|
||||
// Drop the departed train's link and fall into the day-only resubmit
|
||||
// path below — same machinery as OPERATION_CHANGES_REQUESTED.
|
||||
await this.bookingsRepository.update(booking.id, {
|
||||
status: 'OPERATION_CHANGES_REQUESTED',
|
||||
trainScheduleId: null,
|
||||
} as never);
|
||||
booking.status = 'OPERATION_CHANGES_REQUESTED';
|
||||
booking.trainScheduleId = null;
|
||||
}
|
||||
// Path B: only GL Ethiopia completes a customs instance — the customer
|
||||
// never enters shipment data on a customs contract.
|
||||
if (contract.customsClearingEnabled) {
|
||||
|
||||
Reference in New Issue
Block a user