mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-30 12:18:11 +00:00
Merge pull request #404 from Tria-plc/truckassign
Truckassign Import: customer can assign truck when there is no last-mile delivery. Export: customer can assign truck when there is no first-mile pickup. Other/domestic: customer can assign truck only when neither first nor last mile is selected. Booking must still be PAID and in an allowed status.
This commit is contained in:
@@ -23,6 +23,7 @@
|
|||||||
"seed:import-djibouti-demo": "ts-node -r tsconfig-paths/register src/scripts/seed-import-djibouti-demo.ts",
|
"seed:import-djibouti-demo": "ts-node -r tsconfig-paths/register src/scripts/seed-import-djibouti-demo.ts",
|
||||||
"seed:approved-first-lastmile-demo-bookings": "ts-node -r tsconfig-paths/register src/scripts/seed-approved-first-lastmile-demo-bookings.ts",
|
"seed:approved-first-lastmile-demo-bookings": "ts-node -r tsconfig-paths/register src/scripts/seed-approved-first-lastmile-demo-bookings.ts",
|
||||||
"seed:negad-indode-arrived-train": "ts-node -r tsconfig-paths/register src/scripts/seed-negad-indode-arrived-train.ts",
|
"seed:negad-indode-arrived-train": "ts-node -r tsconfig-paths/register src/scripts/seed-negad-indode-arrived-train.ts",
|
||||||
|
"seed:gate-pass-train-scenarios": "ts-node -r tsconfig-paths/register src/scripts/seed-gate-pass-train-scenarios.ts",
|
||||||
"auto-unload:arrived-import-trains": "ts-node -r tsconfig-paths/register src/scripts/auto-unload-arrived-import-trains.ts",
|
"auto-unload:arrived-import-trains": "ts-node -r tsconfig-paths/register src/scripts/auto-unload-arrived-import-trains.ts",
|
||||||
"seed:file-upload-settings": "ts-node -r tsconfig-paths/register src/scripts/seed-file-upload-settings.ts",
|
"seed:file-upload-settings": "ts-node -r tsconfig-paths/register src/scripts/seed-file-upload-settings.ts",
|
||||||
"seed:gov-companies": "ts-node -r tsconfig-paths/register src/scripts/seed-gov-companies.ts",
|
"seed:gov-companies": "ts-node -r tsconfig-paths/register src/scripts/seed-gov-companies.ts",
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ import { FreightPermissionKeyMigrationSeeder } from "./seed/freight-permission-k
|
|||||||
import { DemoFreightDataSeeder } from "./seed/demo-freight-data.seeder";
|
import { DemoFreightDataSeeder } from "./seed/demo-freight-data.seeder";
|
||||||
import { GovCompaniesSeeder } from "./seed/gov-companies.seeder";
|
import { GovCompaniesSeeder } from "./seed/gov-companies.seeder";
|
||||||
import { ApprovedFirstLastMileDemoBookingsSeeder } from "./seed/approved-first-lastmile-demo-bookings.seeder";
|
import { ApprovedFirstLastMileDemoBookingsSeeder } from "./seed/approved-first-lastmile-demo-bookings.seeder";
|
||||||
|
import { PaidIndodeDemoBookingsSeeder } from "./seed/paid-indode-demo-bookings.seeder";
|
||||||
//New Trains, Wagons, Container and Cargo management modules
|
//New Trains, Wagons, Container and Cargo management modules
|
||||||
import { TrainsModule } from "./modules/trains/trains.module";
|
import { TrainsModule } from "./modules/trains/trains.module";
|
||||||
import { WagonsModule } from './modules/wagons/wagons.module';
|
import { WagonsModule } from './modules/wagons/wagons.module';
|
||||||
@@ -160,6 +161,7 @@ import { ImportOperationsModule } from './modules/import-operations/import-opera
|
|||||||
ExportDjiboutiInterchangeDemoSeeder,
|
ExportDjiboutiInterchangeDemoSeeder,
|
||||||
MarshallingDemoTrainsSeeder,
|
MarshallingDemoTrainsSeeder,
|
||||||
ApprovedFirstLastMileDemoBookingsSeeder,
|
ApprovedFirstLastMileDemoBookingsSeeder,
|
||||||
|
PaidIndodeDemoBookingsSeeder,
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
export class AppModule implements OnApplicationBootstrap {
|
export class AppModule implements OnApplicationBootstrap {
|
||||||
@@ -178,6 +180,7 @@ export class AppModule implements OnApplicationBootstrap {
|
|||||||
private readonly warehouseDemoSeeder: WarehouseDemoSeeder,
|
private readonly warehouseDemoSeeder: WarehouseDemoSeeder,
|
||||||
private readonly exportDjiboutiInterchangeDemoSeeder: ExportDjiboutiInterchangeDemoSeeder,
|
private readonly exportDjiboutiInterchangeDemoSeeder: ExportDjiboutiInterchangeDemoSeeder,
|
||||||
private readonly marshallingDemoTrainsSeeder: MarshallingDemoTrainsSeeder,
|
private readonly marshallingDemoTrainsSeeder: MarshallingDemoTrainsSeeder,
|
||||||
|
private readonly paidIndodeDemoBookingsSeeder: PaidIndodeDemoBookingsSeeder,
|
||||||
private readonly freightPermissionKeyMigrationSeeder: FreightPermissionKeyMigrationSeeder,
|
private readonly freightPermissionKeyMigrationSeeder: FreightPermissionKeyMigrationSeeder,
|
||||||
private readonly demoFreightDataSeeder: DemoFreightDataSeeder,
|
private readonly demoFreightDataSeeder: DemoFreightDataSeeder,
|
||||||
private readonly govCompaniesSeeder: GovCompaniesSeeder,
|
private readonly govCompaniesSeeder: GovCompaniesSeeder,
|
||||||
@@ -199,6 +202,7 @@ export class AppModule implements OnApplicationBootstrap {
|
|||||||
await this.warehouseDemoSeeder.run();
|
await this.warehouseDemoSeeder.run();
|
||||||
await this.exportDjiboutiInterchangeDemoSeeder.run();
|
await this.exportDjiboutiInterchangeDemoSeeder.run();
|
||||||
await this.marshallingDemoTrainsSeeder.run();
|
await this.marshallingDemoTrainsSeeder.run();
|
||||||
|
await this.paidIndodeDemoBookingsSeeder.run();
|
||||||
// Idempotent demo data: ≥100 wagons/type, approval chains, 4 staff users.
|
// Idempotent demo data: ≥100 wagons/type, approval chains, 4 staff users.
|
||||||
// Each block self-guards on an empty-table check, so this is safe every boot.
|
// Each block self-guards on an empty-table check, so this is safe every boot.
|
||||||
// Demo data seeds (DemoBookingsSeeder, PricingDataSeeder,
|
// Demo data seeds (DemoBookingsSeeder, PricingDataSeeder,
|
||||||
|
|||||||
@@ -116,6 +116,7 @@ export default registerAs("database", (): TypeOrmModuleOptions => {
|
|||||||
freightMigrationsGlob,
|
freightMigrationsGlob,
|
||||||
],
|
],
|
||||||
migrationsRun: true,
|
migrationsRun: true,
|
||||||
|
migrationsTransactionMode: "each",
|
||||||
// Schema changes via migrations only (synchronize breaks ITMLS backfill on existing rows).
|
// Schema changes via migrations only (synchronize breaks ITMLS backfill on existing rows).
|
||||||
synchronize: false,
|
synchronize: false,
|
||||||
logging:
|
logging:
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ export class AddWarehouseAllocationAndFeeRules1791000000000 implements Migration
|
|||||||
{ name: 'zone_id', type: 'uuid', isNullable: true },
|
{ name: 'zone_id', type: 'uuid', isNullable: true },
|
||||||
{ name: 'free_days', type: 'int', default: 0 },
|
{ name: 'free_days', type: 'int', default: 0 },
|
||||||
{ name: 'rate_per_day', type: 'numeric', precision: 14, scale: 2, default: 0 },
|
{ name: 'rate_per_day', type: 'numeric', precision: 14, scale: 2, default: 0 },
|
||||||
|
{ name: 'tiers', type: 'jsonb', default: "'[]'" },
|
||||||
{ name: 'currency', type: 'varchar', length: '8', default: "'USD'" },
|
{ name: 'currency', type: 'varchar', length: '8', default: "'USD'" },
|
||||||
{ name: 'is_active', type: 'boolean', default: true },
|
{ name: 'is_active', type: 'boolean', default: true },
|
||||||
{ name: 'created_at', type: 'timestamptz', default: 'now()' },
|
{ name: 'created_at', type: 'timestamptz', default: 'now()' },
|
||||||
|
|||||||
@@ -62,20 +62,96 @@ export class CreateInvoices1821000000002 implements MigrationInterface {
|
|||||||
`);
|
`);
|
||||||
|
|
||||||
await queryRunner.query(
|
await queryRunner.query(
|
||||||
`CREATE INDEX idx_invoices_company ON freight.invoices (company_id);`,
|
`
|
||||||
|
ALTER TABLE freight.invoices
|
||||||
|
ADD COLUMN IF NOT EXISTS id uuid DEFAULT uuid_generate_v4(),
|
||||||
|
ADD COLUMN IF NOT EXISTS invoice_number varchar(64),
|
||||||
|
ADD COLUMN IF NOT EXISTS company_id uuid,
|
||||||
|
ADD COLUMN IF NOT EXISTS company_profile_id uuid,
|
||||||
|
ADD COLUMN IF NOT EXISTS total_amount numeric(14, 2) NOT NULL DEFAULT 0,
|
||||||
|
ADD COLUMN IF NOT EXISTS currency varchar(8) NOT NULL DEFAULT 'ETB',
|
||||||
|
ADD COLUMN IF NOT EXISTS status freight.invoices_status_enum NOT NULL DEFAULT 'DRAFT',
|
||||||
|
ADD COLUMN IF NOT EXISTS source varchar(255),
|
||||||
|
ADD COLUMN IF NOT EXISTS source_id varchar(255),
|
||||||
|
ADD COLUMN IF NOT EXISTS type varchar(255),
|
||||||
|
ADD COLUMN IF NOT EXISTS issued_at timestamptz,
|
||||||
|
ADD COLUMN IF NOT EXISTS payment_id uuid,
|
||||||
|
ADD COLUMN IF NOT EXISTS due_at timestamptz,
|
||||||
|
ADD COLUMN IF NOT EXISTS created_at timestamptz NOT NULL DEFAULT now(),
|
||||||
|
ADD COLUMN IF NOT EXISTS updated_at timestamptz NOT NULL DEFAULT now(),
|
||||||
|
ADD COLUMN IF NOT EXISTS deleted_at timestamptz;
|
||||||
|
`,
|
||||||
|
);
|
||||||
|
await queryRunner.query(`
|
||||||
|
UPDATE freight.invoices
|
||||||
|
SET due_at = COALESCE(due_at, issued_at, created_at, now())
|
||||||
|
WHERE due_at IS NULL;
|
||||||
|
`);
|
||||||
|
await queryRunner.query(`ALTER TABLE freight.invoices ALTER COLUMN due_at SET NOT NULL;`);
|
||||||
|
|
||||||
|
await queryRunner.query(`
|
||||||
|
DO $$
|
||||||
|
BEGIN
|
||||||
|
IF NOT EXISTS (
|
||||||
|
SELECT 1 FROM pg_constraint
|
||||||
|
WHERE contype = 'p'
|
||||||
|
AND conrelid = 'freight.invoices'::regclass
|
||||||
|
) THEN
|
||||||
|
ALTER TABLE freight.invoices ADD CONSTRAINT pk_invoices PRIMARY KEY (id);
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
IF NOT EXISTS (
|
||||||
|
SELECT 1 FROM pg_constraint
|
||||||
|
WHERE conname = 'uq_invoices_invoice_number'
|
||||||
|
AND conrelid = 'freight.invoices'::regclass
|
||||||
|
) THEN
|
||||||
|
ALTER TABLE freight.invoices ADD CONSTRAINT uq_invoices_invoice_number UNIQUE (invoice_number);
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
IF NOT EXISTS (
|
||||||
|
SELECT 1 FROM pg_constraint
|
||||||
|
WHERE conname = 'fk_invoices_company'
|
||||||
|
AND conrelid = 'freight.invoices'::regclass
|
||||||
|
) THEN
|
||||||
|
ALTER TABLE freight.invoices ADD CONSTRAINT fk_invoices_company
|
||||||
|
FOREIGN KEY (company_id) REFERENCES freight.companies (id) ON DELETE RESTRICT;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
IF NOT EXISTS (
|
||||||
|
SELECT 1 FROM pg_constraint
|
||||||
|
WHERE conname = 'fk_invoices_company_profile'
|
||||||
|
AND conrelid = 'freight.invoices'::regclass
|
||||||
|
) THEN
|
||||||
|
ALTER TABLE freight.invoices ADD CONSTRAINT fk_invoices_company_profile
|
||||||
|
FOREIGN KEY (company_profile_id) REFERENCES freight.company_profiles (id) ON DELETE RESTRICT;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
IF NOT EXISTS (
|
||||||
|
SELECT 1 FROM pg_constraint
|
||||||
|
WHERE conname = 'fk_invoices_payment'
|
||||||
|
AND conrelid = 'freight.invoices'::regclass
|
||||||
|
) THEN
|
||||||
|
ALTER TABLE freight.invoices ADD CONSTRAINT fk_invoices_payment
|
||||||
|
FOREIGN KEY (payment_id) REFERENCES freight.payments (id) ON DELETE SET NULL;
|
||||||
|
END IF;
|
||||||
|
END $$;
|
||||||
|
`);
|
||||||
|
|
||||||
|
await queryRunner.query(
|
||||||
|
`CREATE INDEX IF NOT EXISTS idx_invoices_company ON freight.invoices (company_id);`,
|
||||||
);
|
);
|
||||||
await queryRunner.query(
|
await queryRunner.query(
|
||||||
`CREATE INDEX idx_invoices_company_profile ON freight.invoices (company_profile_id);`,
|
`CREATE INDEX IF NOT EXISTS idx_invoices_company_profile ON freight.invoices (company_profile_id);`,
|
||||||
);
|
);
|
||||||
await queryRunner.query(
|
await queryRunner.query(
|
||||||
`CREATE INDEX idx_invoices_source ON freight.invoices (source, source_id);`,
|
`CREATE INDEX IF NOT EXISTS idx_invoices_source ON freight.invoices (source, source_id);`,
|
||||||
);
|
);
|
||||||
await queryRunner.query(
|
await queryRunner.query(
|
||||||
`CREATE INDEX idx_invoices_status ON freight.invoices (status);`,
|
`CREATE INDEX IF NOT EXISTS idx_invoices_status ON freight.invoices (status);`,
|
||||||
);
|
);
|
||||||
|
|
||||||
await queryRunner.query(`
|
await queryRunner.query(`
|
||||||
CREATE TABLE freight.invoice_lines (
|
CREATE TABLE IF NOT EXISTS freight.invoice_lines (
|
||||||
id uuid NOT NULL DEFAULT uuid_generate_v4(),
|
id uuid NOT NULL DEFAULT uuid_generate_v4(),
|
||||||
invoice_id uuid NOT NULL,
|
invoice_id uuid NOT NULL,
|
||||||
charge_type varchar NOT NULL,
|
charge_type varchar NOT NULL,
|
||||||
@@ -95,7 +171,7 @@ export class CreateInvoices1821000000002 implements MigrationInterface {
|
|||||||
`);
|
`);
|
||||||
|
|
||||||
await queryRunner.query(
|
await queryRunner.query(
|
||||||
`CREATE INDEX idx_invoice_lines_invoice ON freight.invoice_lines (invoice_id);`,
|
`CREATE INDEX IF NOT EXISTS idx_invoice_lines_invoice ON freight.invoice_lines (invoice_id);`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,31 @@ export class CentralizeWarehouseInvoices1829000000000 implements MigrationInterf
|
|||||||
name = 'CentralizeWarehouseInvoices1829000000000';
|
name = 'CentralizeWarehouseInvoices1829000000000';
|
||||||
|
|
||||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(`
|
||||||
|
DO $$
|
||||||
|
BEGIN
|
||||||
|
IF EXISTS (
|
||||||
|
SELECT 1
|
||||||
|
FROM information_schema.columns
|
||||||
|
WHERE table_schema = 'freight'
|
||||||
|
AND table_name = 'invoices'
|
||||||
|
AND column_name = 'booking_id'
|
||||||
|
) THEN
|
||||||
|
ALTER TABLE freight.invoices ALTER COLUMN booking_id DROP NOT NULL;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
IF EXISTS (
|
||||||
|
SELECT 1
|
||||||
|
FROM information_schema.columns
|
||||||
|
WHERE table_schema = 'freight'
|
||||||
|
AND table_name = 'invoices'
|
||||||
|
AND column_name = 'amount'
|
||||||
|
) THEN
|
||||||
|
ALTER TABLE freight.invoices ALTER COLUMN amount DROP NOT NULL;
|
||||||
|
END IF;
|
||||||
|
END $$;
|
||||||
|
`);
|
||||||
|
|
||||||
// 1. Invoice headers. Keep the same id so items still link, and so any
|
// 1. Invoice headers. Keep the same id so items still link, and so any
|
||||||
// external reference to the invoice id stays valid.
|
// external reference to the invoice id stays valid.
|
||||||
await queryRunner.query(`
|
await queryRunner.query(`
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||||
|
|
||||||
|
export class AddWarehouseFeeRuleTiers1831000000000 implements MigrationInterface {
|
||||||
|
name = 'AddWarehouseFeeRuleTiers1831000000000';
|
||||||
|
|
||||||
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(`
|
||||||
|
ALTER TABLE freight.warehouse_fee_rules
|
||||||
|
ADD COLUMN IF NOT EXISTS tiers jsonb NOT NULL DEFAULT '[]';
|
||||||
|
`);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(`
|
||||||
|
ALTER TABLE freight.warehouse_fee_rules
|
||||||
|
DROP COLUMN IF EXISTS tiers;
|
||||||
|
`);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||||
|
|
||||||
|
export class AddCustomerTruckAssignmentToBookings1832000000000 implements MigrationInterface {
|
||||||
|
name = 'AddCustomerTruckAssignmentToBookings1832000000000';
|
||||||
|
|
||||||
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(`
|
||||||
|
ALTER TABLE freight.bookings
|
||||||
|
ADD COLUMN IF NOT EXISTS customer_truck_plate_number varchar(32),
|
||||||
|
ADD COLUMN IF NOT EXISTS customer_truck_driver_name varchar(120),
|
||||||
|
ADD COLUMN IF NOT EXISTS customer_truck_type varchar(60),
|
||||||
|
ADD COLUMN IF NOT EXISTS customer_truck_container_number varchar(16),
|
||||||
|
ADD COLUMN IF NOT EXISTS customer_truck_assigned_at timestamptz,
|
||||||
|
ADD COLUMN IF NOT EXISTS customer_truck_arrived_at timestamptz
|
||||||
|
`);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(`
|
||||||
|
ALTER TABLE freight.bookings
|
||||||
|
DROP COLUMN IF EXISTS customer_truck_arrived_at,
|
||||||
|
DROP COLUMN IF EXISTS customer_truck_assigned_at,
|
||||||
|
DROP COLUMN IF EXISTS customer_truck_container_number,
|
||||||
|
DROP COLUMN IF EXISTS customer_truck_type,
|
||||||
|
DROP COLUMN IF EXISTS customer_truck_driver_name,
|
||||||
|
DROP COLUMN IF EXISTS customer_truck_plate_number
|
||||||
|
`);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -867,6 +867,11 @@ export class BillingService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const amountDue = Number(invoice.balanceAmount ?? invoice.totalAmount);
|
||||||
|
if (!(amountDue > 0)) {
|
||||||
|
throw new BadRequestException("Invoice has no outstanding balance.");
|
||||||
|
}
|
||||||
|
|
||||||
const result = await this.payment.initiate({
|
const result = await this.payment.initiate({
|
||||||
referenceId: invoice.sourceId,
|
referenceId: invoice.sourceId,
|
||||||
source: invoice.source,
|
source: invoice.source,
|
||||||
|
|||||||
@@ -58,10 +58,11 @@ import {
|
|||||||
RequestOperationDto,
|
RequestOperationDto,
|
||||||
OperationReviewDto,
|
OperationReviewDto,
|
||||||
StaffRejectDto,
|
StaffRejectDto,
|
||||||
} from "./dto/request-changes.dto";
|
} from './dto/request-changes.dto';
|
||||||
import { ContractViewDto } from "./dto/contract-view.dto";
|
import { ContractViewDto } from './dto/contract-view.dto';
|
||||||
import { SignContractDto } from "./dto/sign-contract.dto";
|
import { CustomerTruckAssignmentDto } from './dto/customer-truck-assignment.dto';
|
||||||
import { UpdateBookingDto } from "./dto/update-booking.dto";
|
import { SignContractDto } from './dto/sign-contract.dto';
|
||||||
|
import { UpdateBookingDto } from './dto/update-booking.dto';
|
||||||
import {
|
import {
|
||||||
type AuthUserPayload,
|
type AuthUserPayload,
|
||||||
resolveAuthUserId,
|
resolveAuthUserId,
|
||||||
@@ -275,7 +276,40 @@ export class BookingsController {
|
|||||||
return this.transitionService.enrichBookingResponse(booking);
|
return this.transitionService.enrichBookingResponse(booking);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get(":id/tracking")
|
@Post(':id/customer-truck-assignment')
|
||||||
|
@ApiOperation({ summary: 'Customer assigns external truck and driver for terminal pickup' })
|
||||||
|
async assignCustomerTruck(
|
||||||
|
@Param('id', ParseUUIDPipe) id: string,
|
||||||
|
@Body() dto: CustomerTruckAssignmentDto,
|
||||||
|
@CurrentUser() user: TCurrentUser,
|
||||||
|
) {
|
||||||
|
const booking = await this.bookingsService.findById(id);
|
||||||
|
if (!hasFreightPermission(user, FREIGHT_PERMS.bookings.view)) {
|
||||||
|
await this.bookingsService.assertCustomerCanAccessBooking(user?.id, booking);
|
||||||
|
}
|
||||||
|
const assigned = await this.bookingsService.assignCustomerTruck(id, dto);
|
||||||
|
return this.transitionService.enrichBookingResponse(assigned);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get(':id/customer-truck-assignment/freight-order')
|
||||||
|
@ApiOperation({ summary: 'Download duplicate freight order copies for customer truck assignment' })
|
||||||
|
async customerTruckFreightOrder(
|
||||||
|
@Param('id', ParseUUIDPipe) id: string,
|
||||||
|
@CurrentUser() user: TCurrentUser,
|
||||||
|
@Res() res: Response,
|
||||||
|
) {
|
||||||
|
const booking = await this.bookingsService.findById(id);
|
||||||
|
if (!hasFreightPermission(user, FREIGHT_PERMS.bookings.view)) {
|
||||||
|
await this.bookingsService.assertCustomerCanAccessBooking(user?.id, booking);
|
||||||
|
}
|
||||||
|
const { filename, buffer } =
|
||||||
|
await this.bookingsService.customerTruckFreightOrderCopies(id);
|
||||||
|
res.setHeader('Content-Type', 'application/pdf');
|
||||||
|
res.setHeader('Content-Disposition', `attachment; filename="${filename}"`);
|
||||||
|
res.send(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get(':id/tracking')
|
||||||
@ApiOperation({
|
@ApiOperation({
|
||||||
summary: "Shipment tracking timeline for a booking",
|
summary: "Shipment tracking timeline for a booking",
|
||||||
description:
|
description:
|
||||||
|
|||||||
@@ -45,6 +45,8 @@ import {
|
|||||||
import { Booking } from './entities/booking.entity';
|
import { Booking } from './entities/booking.entity';
|
||||||
import { BookingContainerAllocation } from './entities/booking-container-allocation.entity';
|
import { BookingContainerAllocation } from './entities/booking-container-allocation.entity';
|
||||||
import { FileRecord } from '../files/entities/file.entity';
|
import { FileRecord } from '../files/entities/file.entity';
|
||||||
|
import { CustomerTruckAssignmentDto } from './dto/customer-truck-assignment.dto';
|
||||||
|
import { ContractPdfService } from '../../contracts/contract-pdf.service';
|
||||||
|
|
||||||
/** Paginated booking list: flat `total` (backoffice) + `meta` block (portal). */
|
/** Paginated booking list: flat `total` (backoffice) + `meta` block (portal). */
|
||||||
export interface PaginatedBookings {
|
export interface PaginatedBookings {
|
||||||
@@ -92,8 +94,62 @@ export class BookingsService {
|
|||||||
private readonly ruleEngineService: RuleEngineService,
|
private readonly ruleEngineService: RuleEngineService,
|
||||||
private readonly containerTypesService: ContainerTypesService,
|
private readonly containerTypesService: ContainerTypesService,
|
||||||
private readonly consolidationService: ConsolidationService,
|
private readonly consolidationService: ConsolidationService,
|
||||||
|
private readonly contractPdfService: ContractPdfService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
|
async assignCustomerTruck(
|
||||||
|
bookingId: string,
|
||||||
|
dto: CustomerTruckAssignmentDto,
|
||||||
|
): Promise<Booking> {
|
||||||
|
const booking = await this.findById(bookingId);
|
||||||
|
const hasFirstMile = Boolean(booking.firstMilePickupAddress?.trim());
|
||||||
|
const hasLastMile = Boolean(booking.lastMileDeliveryAddress?.trim());
|
||||||
|
const usesMileService =
|
||||||
|
booking.tradeDirection === 'IMPORT'
|
||||||
|
? hasLastMile
|
||||||
|
: booking.tradeDirection === 'EXPORT'
|
||||||
|
? hasFirstMile
|
||||||
|
: hasFirstMile || hasLastMile;
|
||||||
|
if (usesMileService) {
|
||||||
|
throw new BadRequestException(
|
||||||
|
'Customer truck assignment is only allowed when first/last mile delivery is not selected',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (booking.customerTruckAssignedAt) {
|
||||||
|
throw new ConflictException('Customer truck assignment is already submitted and locked');
|
||||||
|
}
|
||||||
|
if (booking.paymentStatus !== 'PAID') {
|
||||||
|
throw new BadRequestException('Booking must be paid before assigning an external customer truck');
|
||||||
|
}
|
||||||
|
|
||||||
|
await this.bookingsRepository.update(bookingId, {
|
||||||
|
status: 'TRUCK_ASSIGNED',
|
||||||
|
customerTruckPlateNumber: dto.truckPlateNumber.trim().toUpperCase(),
|
||||||
|
customerTruckDriverName: dto.driverName.trim(),
|
||||||
|
customerTruckType: dto.truckType.trim(),
|
||||||
|
customerTruckContainerNumber: dto.containerNumberToLoad.trim().toUpperCase(),
|
||||||
|
customerTruckAssignedAt: new Date(),
|
||||||
|
});
|
||||||
|
|
||||||
|
return this.findById(bookingId);
|
||||||
|
}
|
||||||
|
|
||||||
|
async customerTruckFreightOrderCopies(
|
||||||
|
bookingId: string,
|
||||||
|
): Promise<{ filename: string; buffer: Buffer }> {
|
||||||
|
const booking = await this.findById(bookingId);
|
||||||
|
if (!booking.customerTruckAssignedAt) {
|
||||||
|
throw new BadRequestException('Customer truck must be assigned before freight order copies can be generated');
|
||||||
|
}
|
||||||
|
|
||||||
|
const html = this.buildCustomerTruckFreightOrderHtml(booking);
|
||||||
|
const buffer = await this.contractPdfService.htmlToPdfBuffer(html);
|
||||||
|
return {
|
||||||
|
filename: `freight-order-${booking.reference.replace(/[^a-zA-Z0-9_-]+/g, '-')}.pdf`,
|
||||||
|
buffer,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/** Resolve trade direction from yard countries; reject client mismatch. */
|
/** Resolve trade direction from yard countries; reject client mismatch. */
|
||||||
private async resolveTradeDirectionForBooking(
|
private async resolveTradeDirectionForBooking(
|
||||||
originYardId: string,
|
originYardId: string,
|
||||||
@@ -131,6 +187,79 @@ export class BookingsService {
|
|||||||
return `BK-${year}-${String(count + 1).padStart(6, '0')}`;
|
return `BK-${year}-${String(count + 1).padStart(6, '0')}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private buildCustomerTruckFreightOrderHtml(booking: Booking): string {
|
||||||
|
const assignedAt = booking.customerTruckAssignedAt
|
||||||
|
? new Date(booking.customerTruckAssignedAt).toLocaleString('en-GB')
|
||||||
|
: '-';
|
||||||
|
const rows: Array<[string, string | null | undefined]> = [
|
||||||
|
['Booking Reference', booking.reference],
|
||||||
|
['Client Name', booking.company?.name],
|
||||||
|
['Client ID', booking.companyId],
|
||||||
|
['Trade Direction', booking.tradeDirection],
|
||||||
|
['Freight Type', booking.freightType],
|
||||||
|
['Truck Plate Number', booking.customerTruckPlateNumber],
|
||||||
|
['Driver Name', booking.customerTruckDriverName],
|
||||||
|
['Truck Type', booking.customerTruckType],
|
||||||
|
['Container Number to Load', booking.customerTruckContainerNumber],
|
||||||
|
['Assigned At', assignedAt],
|
||||||
|
['Booking Status', booking.status],
|
||||||
|
];
|
||||||
|
const rowHtml = rows
|
||||||
|
.map(([label, value]) => `<tr><th>${this.escapeHtml(label)}</th><td>${this.escapeHtml(value || '-')}</td></tr>`)
|
||||||
|
.join('');
|
||||||
|
const copy = (watermark: string) => `
|
||||||
|
<section class="copy">
|
||||||
|
<div class="watermark">${this.escapeHtml(watermark)}</div>
|
||||||
|
<header>
|
||||||
|
<div>
|
||||||
|
<h1>Freight Order</h1>
|
||||||
|
<p>Customer external truck assignment</p>
|
||||||
|
</div>
|
||||||
|
<strong>${this.escapeHtml(booking.reference)}</strong>
|
||||||
|
</header>
|
||||||
|
<table>${rowHtml}</table>
|
||||||
|
<div class="signatures">
|
||||||
|
<div>Customer / Carrier Signature</div>
|
||||||
|
<div>Port Operations Verification</div>
|
||||||
|
<div>Gate Security Verification</div>
|
||||||
|
</div>
|
||||||
|
</section>`;
|
||||||
|
|
||||||
|
return `<!doctype html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<style>
|
||||||
|
body { font-family: Arial, sans-serif; color: #10202f; margin: 0; }
|
||||||
|
.copy { position: relative; min-height: 46vh; padding: 28px 32px; page-break-inside: avoid; border-bottom: 1px dashed #94a3b8; }
|
||||||
|
.watermark { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 34px; font-weight: 800; color: rgba(16, 32, 47, 0.08); transform: rotate(-18deg); pointer-events: none; }
|
||||||
|
header { display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 3px solid #0a9f6a; padding-bottom: 14px; margin-bottom: 18px; }
|
||||||
|
h1 { margin: 0; font-size: 28px; letter-spacing: 0; }
|
||||||
|
p { margin: 4px 0 0; color: #64748b; }
|
||||||
|
strong { font-size: 16px; color: #0a9f6a; }
|
||||||
|
table { width: 100%; border-collapse: collapse; position: relative; z-index: 1; }
|
||||||
|
th, td { border: 1px solid #cbd5e1; padding: 9px 10px; text-align: left; font-size: 12px; }
|
||||||
|
th { width: 34%; background: #f1f5f9; }
|
||||||
|
.signatures { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-top: 34px; font-size: 11px; color: #475569; position: relative; z-index: 1; }
|
||||||
|
.signatures div { border-top: 1px solid #334155; padding-top: 8px; min-height: 28px; }
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
${copy('Copy 1: Port Operations Copy')}
|
||||||
|
${copy('Copy 2: Gate Security & Carrier Copy')}
|
||||||
|
</body>
|
||||||
|
</html>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
private escapeHtml(value: string): string {
|
||||||
|
return value
|
||||||
|
.replace(/&/g, '&')
|
||||||
|
.replace(/</g, '<')
|
||||||
|
.replace(/>/g, '>')
|
||||||
|
.replace(/"/g, '"')
|
||||||
|
.replace(/'/g, ''');
|
||||||
|
}
|
||||||
|
|
||||||
/** Build evaluation input from booking freight shape. */
|
/** Build evaluation input from booking freight shape. */
|
||||||
/**
|
/**
|
||||||
* Whether a service type bundles customs clearance. This is the single source
|
* Whether a service type bundles customs clearance. This is the single source
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
import { IsIn, IsNotEmpty, IsString, Matches, MaxLength } from 'class-validator';
|
||||||
|
|
||||||
|
export const CUSTOMER_TRUCK_TYPES = [
|
||||||
|
'Flatbed',
|
||||||
|
'Container Chassis',
|
||||||
|
'Lowboy',
|
||||||
|
'Box Truck',
|
||||||
|
'Tipper',
|
||||||
|
] as const;
|
||||||
|
|
||||||
|
export class CustomerTruckAssignmentDto {
|
||||||
|
@IsString()
|
||||||
|
@IsNotEmpty()
|
||||||
|
@MaxLength(32)
|
||||||
|
truckPlateNumber!: string;
|
||||||
|
|
||||||
|
@IsString()
|
||||||
|
@IsNotEmpty()
|
||||||
|
@MaxLength(120)
|
||||||
|
driverName!: string;
|
||||||
|
|
||||||
|
@IsString()
|
||||||
|
@IsNotEmpty()
|
||||||
|
@IsIn(CUSTOMER_TRUCK_TYPES)
|
||||||
|
truckType!: string;
|
||||||
|
|
||||||
|
@IsString()
|
||||||
|
@IsNotEmpty()
|
||||||
|
@MaxLength(16)
|
||||||
|
@Matches(/^[A-Z]{4}\d{7}$/, {
|
||||||
|
message: 'containerNumberToLoad must match ISO container format, e.g. ABCD1234567',
|
||||||
|
})
|
||||||
|
containerNumberToLoad!: string;
|
||||||
|
}
|
||||||
@@ -51,6 +51,7 @@ export const BOOKING_STATUSES = [
|
|||||||
// Road (truck) drawdown orders skip the train batch pool and wait here for
|
// Road (truck) drawdown orders skip the train batch pool and wait here for
|
||||||
// truck dispatch after Marketing accepts; billed by KM, not wagons.
|
// truck dispatch after Marketing accepts; billed by KM, not wagons.
|
||||||
'ROAD_DISPATCH_PENDING',
|
'ROAD_DISPATCH_PENDING',
|
||||||
|
'TRUCK_ASSIGNED',
|
||||||
'OPERATION_REQUESTED',
|
'OPERATION_REQUESTED',
|
||||||
// Operations review gate: customer picks a schedule day and submits the
|
// Operations review gate: customer picks a schedule day and submits the
|
||||||
// operation request; the operations team reviews capacity/docs/route before
|
// operation request; the operations team reviews capacity/docs/route before
|
||||||
@@ -260,6 +261,24 @@ export class Booking extends BaseEntity {
|
|||||||
@Column({ name: 'last_mile_delivery_lng', type: 'numeric', precision: 10, scale: 7, nullable: true })
|
@Column({ name: 'last_mile_delivery_lng', type: 'numeric', precision: 10, scale: 7, nullable: true })
|
||||||
lastMileDeliveryLng?: number | null;
|
lastMileDeliveryLng?: number | null;
|
||||||
|
|
||||||
|
@Column({ name: 'customer_truck_plate_number', type: 'varchar', length: 32, nullable: true })
|
||||||
|
customerTruckPlateNumber?: string | null;
|
||||||
|
|
||||||
|
@Column({ name: 'customer_truck_driver_name', type: 'varchar', length: 120, nullable: true })
|
||||||
|
customerTruckDriverName?: string | null;
|
||||||
|
|
||||||
|
@Column({ name: 'customer_truck_type', type: 'varchar', length: 60, nullable: true })
|
||||||
|
customerTruckType?: string | null;
|
||||||
|
|
||||||
|
@Column({ name: 'customer_truck_container_number', type: 'varchar', length: 16, nullable: true })
|
||||||
|
customerTruckContainerNumber?: string | null;
|
||||||
|
|
||||||
|
@Column({ name: 'customer_truck_assigned_at', type: 'timestamptz', nullable: true })
|
||||||
|
customerTruckAssignedAt?: Date | null;
|
||||||
|
|
||||||
|
@Column({ name: 'customer_truck_arrived_at', type: 'timestamptz', nullable: true })
|
||||||
|
customerTruckArrivedAt?: Date | null;
|
||||||
|
|
||||||
@Column({ name: 'customs_clearing_enabled', type: 'boolean', default: false })
|
@Column({ name: 'customs_clearing_enabled', type: 'boolean', default: false })
|
||||||
customsClearingEnabled!: boolean;
|
customsClearingEnabled!: boolean;
|
||||||
|
|
||||||
|
|||||||
@@ -131,6 +131,12 @@ export class LastMileService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async create(dto: CreateLastMileDto): Promise<LastMile> {
|
async create(dto: CreateLastMileDto): Promise<LastMile> {
|
||||||
|
const [existing] = await this.lastMileRepository.findAll({
|
||||||
|
where: { bookingId: dto.bookingId },
|
||||||
|
take: 1,
|
||||||
|
});
|
||||||
|
if (existing) return existing;
|
||||||
|
|
||||||
return this.lastMileRepository.create({
|
return this.lastMileRepository.create({
|
||||||
bookingId: dto.bookingId,
|
bookingId: dto.bookingId,
|
||||||
status: dto.status ?? 'READY_TO_TRANSIT',
|
status: dto.status ?? 'READY_TO_TRANSIT',
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
||||||
import { IsIn, IsOptional, IsString } from 'class-validator';
|
import { IsDateString, IsIn, IsOptional, IsString } from 'class-validator';
|
||||||
|
|
||||||
export const IMPORT_DJIBOUTI_DOCUMENT_TYPES = [
|
export const IMPORT_DJIBOUTI_DOCUMENT_TYPES = [
|
||||||
|
'GATE_PASS',
|
||||||
'DELIVERY_ORDER',
|
'DELIVERY_ORDER',
|
||||||
'PORT_INVOICE',
|
'PORT_INVOICE',
|
||||||
'DJIBOUTI_T1',
|
'DJIBOUTI_T1',
|
||||||
@@ -43,6 +44,26 @@ export class UploadImportDjiboutiDocumentDto {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class ImportDjiboutiActionDto {
|
export class ImportDjiboutiActionDto {
|
||||||
|
@ApiPropertyOptional({ description: 'Gate pass secured date/time. Defaults to now.' })
|
||||||
|
@IsOptional()
|
||||||
|
@IsDateString()
|
||||||
|
securedAt?: string;
|
||||||
|
|
||||||
|
@ApiPropertyOptional()
|
||||||
|
@IsOptional()
|
||||||
|
@IsString()
|
||||||
|
fileId?: string;
|
||||||
|
|
||||||
|
@ApiPropertyOptional()
|
||||||
|
@IsOptional()
|
||||||
|
@IsString()
|
||||||
|
fileUrl?: string;
|
||||||
|
|
||||||
|
@ApiPropertyOptional()
|
||||||
|
@IsOptional()
|
||||||
|
@IsString()
|
||||||
|
reference?: string;
|
||||||
|
|
||||||
@ApiPropertyOptional()
|
@ApiPropertyOptional()
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsString()
|
@IsString()
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { Column, Entity, Index, JoinColumn, OneToOne } from 'typeorm';
|
|||||||
import { TrainSchedule } from '../../train-schedules/entities/train-schedule.entity';
|
import { TrainSchedule } from '../../train-schedules/entities/train-schedule.entity';
|
||||||
|
|
||||||
export type ImportDjiboutiDocumentType =
|
export type ImportDjiboutiDocumentType =
|
||||||
|
| 'GATE_PASS'
|
||||||
| 'DELIVERY_ORDER'
|
| 'DELIVERY_ORDER'
|
||||||
| 'PORT_INVOICE'
|
| 'PORT_INVOICE'
|
||||||
| 'DJIBOUTI_T1'
|
| 'DJIBOUTI_T1'
|
||||||
|
|||||||
@@ -54,7 +54,6 @@ import {
|
|||||||
type ImportDjiboutiDocumentType,
|
type ImportDjiboutiDocumentType,
|
||||||
} from './entities/import-djibouti-operation.entity';
|
} from './entities/import-djibouti-operation.entity';
|
||||||
import {
|
import {
|
||||||
IMPORT_DJIBOUTI_DOCUMENT_TYPES,
|
|
||||||
ImportDjiboutiActionDto,
|
ImportDjiboutiActionDto,
|
||||||
UploadImportDjiboutiDocumentDto,
|
UploadImportDjiboutiDocumentDto,
|
||||||
} from './dto/import-djibouti-operation.dto';
|
} from './dto/import-djibouti-operation.dto';
|
||||||
@@ -832,7 +831,7 @@ export class TrainSchedulingService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getImportDjiboutiOperation(scheduleId: string) {
|
async getImportDjiboutiOperation(scheduleId: string) {
|
||||||
const schedule = await this.getImportDjiboutiSchedule(scheduleId);
|
const schedule = await this.getDjiboutiGatepassSchedule(scheduleId);
|
||||||
const operation = await this.getOrCreateImportDjiboutiOperation(scheduleId);
|
const operation = await this.getOrCreateImportDjiboutiOperation(scheduleId);
|
||||||
return this.mapImportDjiboutiOperation(schedule, operation);
|
return this.mapImportDjiboutiOperation(schedule, operation);
|
||||||
}
|
}
|
||||||
@@ -841,7 +840,7 @@ export class TrainSchedulingService {
|
|||||||
scheduleId: string,
|
scheduleId: string,
|
||||||
dto: UploadImportDjiboutiDocumentDto,
|
dto: UploadImportDjiboutiDocumentDto,
|
||||||
) {
|
) {
|
||||||
const schedule = await this.getImportDjiboutiSchedule(scheduleId);
|
const schedule = await this.getDjiboutiGatepassSchedule(scheduleId);
|
||||||
const operation = await this.getOrCreateImportDjiboutiOperation(scheduleId);
|
const operation = await this.getOrCreateImportDjiboutiOperation(scheduleId);
|
||||||
const documents = {
|
const documents = {
|
||||||
...(operation.documents ?? {}),
|
...(operation.documents ?? {}),
|
||||||
@@ -865,21 +864,30 @@ export class TrainSchedulingService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async grantImportDjiboutiGatepass(scheduleId: string, dto: ImportDjiboutiActionDto = {}) {
|
async grantImportDjiboutiGatepass(scheduleId: string, dto: ImportDjiboutiActionDto = {}) {
|
||||||
const schedule = await this.getImportDjiboutiSchedule(scheduleId);
|
const schedule = await this.getDjiboutiGatepassSchedule(scheduleId);
|
||||||
const operation = await this.getOrCreateImportDjiboutiOperation(scheduleId);
|
const operation = await this.getOrCreateImportDjiboutiOperation(scheduleId);
|
||||||
const missing = this.missingImportDjiboutiDocuments(operation);
|
const securedAt = dto.securedAt ? new Date(dto.securedAt) : new Date();
|
||||||
if (missing.length) {
|
const documents = { ...(operation.documents ?? {}) };
|
||||||
throw new BadRequestException(`Gatepass cannot be granted until documents are uploaded: ${missing.join(', ')}`);
|
if (dto.fileId || dto.fileUrl || dto.reference || dto.notes) {
|
||||||
|
documents.GATE_PASS = {
|
||||||
|
fileId: dto.fileId ?? null,
|
||||||
|
fileUrl: dto.fileUrl ?? null,
|
||||||
|
reference: dto.reference ?? null,
|
||||||
|
uploadedAt: new Date().toISOString(),
|
||||||
|
uploadedBy: dto.performedBy ?? null,
|
||||||
|
notes: dto.notes ?? null,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.dataSource.getRepository(ImportDjiboutiOperation).update(operation.id, {
|
await this.dataSource.getRepository(ImportDjiboutiOperation).update(operation.id, {
|
||||||
gatepassGrantedAt: operation.gatepassGrantedAt ?? new Date(),
|
documents,
|
||||||
|
gatepassGrantedAt: securedAt,
|
||||||
performedBy: dto.performedBy ?? operation.performedBy ?? null,
|
performedBy: dto.performedBy ?? operation.performedBy ?? null,
|
||||||
notes: dto.notes ?? operation.notes ?? null,
|
notes: dto.notes ?? operation.notes ?? null,
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(
|
console.log(
|
||||||
`[NOTIFY] Import gatepass granted for train ${schedule.trainNumber ?? schedule.id}; loading may proceed.`,
|
`[NOTIFY] Gate pass secured for train ${schedule.trainNumber ?? schedule.id}; Djibouti Port entry is allowed.`,
|
||||||
);
|
);
|
||||||
return this.getImportDjiboutiOperation(schedule.id);
|
return this.getImportDjiboutiOperation(schedule.id);
|
||||||
}
|
}
|
||||||
@@ -1299,16 +1307,28 @@ export class TrainSchedulingService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async getImportDjiboutiSchedule(scheduleId: string): Promise<TrainSchedule> {
|
private async getImportDjiboutiSchedule(scheduleId: string): Promise<TrainSchedule> {
|
||||||
|
const schedule = await this.getDjiboutiGatepassSchedule(scheduleId);
|
||||||
|
if (!this.isImportDjiboutiSchedule(schedule)) {
|
||||||
|
throw new BadRequestException('This action applies only to IMPORT schedules originating from Djibouti');
|
||||||
|
}
|
||||||
|
return schedule;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async getDjiboutiGatepassSchedule(scheduleId: string): Promise<TrainSchedule> {
|
||||||
const schedule = await this.trainSchedulesRepository.findByIdWithFullGraph(scheduleId);
|
const schedule = await this.trainSchedulesRepository.findByIdWithFullGraph(scheduleId);
|
||||||
if (!schedule) {
|
if (!schedule) {
|
||||||
throw new NotFoundException(`Train schedule ${scheduleId} not found`);
|
throw new NotFoundException(`Train schedule ${scheduleId} not found`);
|
||||||
}
|
}
|
||||||
if (!this.isImportDjiboutiSchedule(schedule)) {
|
if (!this.isDjiboutiGatepassSchedule(schedule)) {
|
||||||
throw new BadRequestException('Batch 7 actions apply only to IMPORT schedules originating from Djibouti');
|
throw new BadRequestException('Gate pass applies only to trains entering Djibouti Port on import or export routes');
|
||||||
}
|
}
|
||||||
return schedule;
|
return schedule;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private isDjiboutiGatepassSchedule(schedule: TrainSchedule): boolean {
|
||||||
|
return this.isImportDjiboutiSchedule(schedule) || this.isExportDjiboutiSchedule(schedule);
|
||||||
|
}
|
||||||
|
|
||||||
private isImportDjiboutiSchedule(schedule: TrainSchedule): boolean {
|
private isImportDjiboutiSchedule(schedule: TrainSchedule): boolean {
|
||||||
const direction =
|
const direction =
|
||||||
(schedule.direction as 'IMPORT' | 'EXPORT' | 'DOMESTIC' | null) ??
|
(schedule.direction as 'IMPORT' | 'EXPORT' | 'DOMESTIC' | null) ??
|
||||||
@@ -1323,6 +1343,20 @@ export class TrainSchedulingService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private isExportDjiboutiSchedule(schedule: TrainSchedule): boolean {
|
||||||
|
const direction =
|
||||||
|
(schedule.direction as 'IMPORT' | 'EXPORT' | 'DOMESTIC' | null) ??
|
||||||
|
(schedule.originStation && schedule.destinationStation
|
||||||
|
? deriveScheduleDirection(schedule.originStation, schedule.destinationStation)
|
||||||
|
: null);
|
||||||
|
return (
|
||||||
|
direction === 'EXPORT' &&
|
||||||
|
this.isDjiboutiPortDestination(
|
||||||
|
`${schedule.destinationStation?.code ?? ''} ${schedule.destinationStation?.label ?? ''}`,
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
private async getOrCreateImportDjiboutiOperation(scheduleId: string): Promise<ImportDjiboutiOperation> {
|
private async getOrCreateImportDjiboutiOperation(scheduleId: string): Promise<ImportDjiboutiOperation> {
|
||||||
const repo = this.dataSource.getRepository(ImportDjiboutiOperation);
|
const repo = this.dataSource.getRepository(ImportDjiboutiOperation);
|
||||||
const existing = await repo.findOne({ where: { trainScheduleId: scheduleId } });
|
const existing = await repo.findOne({ where: { trainScheduleId: scheduleId } });
|
||||||
@@ -1331,8 +1365,8 @@ export class TrainSchedulingService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private missingImportDjiboutiDocuments(operation?: ImportDjiboutiOperation | null): ImportDjiboutiDocumentType[] {
|
private missingImportDjiboutiDocuments(operation?: ImportDjiboutiOperation | null): ImportDjiboutiDocumentType[] {
|
||||||
const documents = operation?.documents ?? {};
|
void operation;
|
||||||
return IMPORT_DJIBOUTI_DOCUMENT_TYPES.filter((type) => !documents[type]);
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
private assertImportDjiboutiGatepassGranted(operation?: ImportDjiboutiOperation | null): void {
|
private assertImportDjiboutiGatepassGranted(operation?: ImportDjiboutiOperation | null): void {
|
||||||
@@ -1343,6 +1377,7 @@ export class TrainSchedulingService {
|
|||||||
|
|
||||||
private mapImportDjiboutiOperation(schedule: TrainSchedule, operation: ImportDjiboutiOperation) {
|
private mapImportDjiboutiOperation(schedule: TrainSchedule, operation: ImportDjiboutiOperation) {
|
||||||
const missingDocuments = this.missingImportDjiboutiDocuments(operation);
|
const missingDocuments = this.missingImportDjiboutiDocuments(operation);
|
||||||
|
const gatepassStatus = operation.gatepassGrantedAt ? 'SECURED' : 'NOT_SECURED';
|
||||||
return {
|
return {
|
||||||
trainScheduleId: schedule.id,
|
trainScheduleId: schedule.id,
|
||||||
trainNumber: schedule.trainNumber ?? null,
|
trainNumber: schedule.trainNumber ?? null,
|
||||||
@@ -1350,6 +1385,7 @@ export class TrainSchedulingService {
|
|||||||
status: {
|
status: {
|
||||||
documentsComplete: missingDocuments.length === 0,
|
documentsComplete: missingDocuments.length === 0,
|
||||||
missingDocuments,
|
missingDocuments,
|
||||||
|
gatepassStatus,
|
||||||
gatepassGranted: Boolean(operation.gatepassGrantedAt),
|
gatepassGranted: Boolean(operation.gatepassGrantedAt),
|
||||||
readyForLoading: Boolean(operation.readyForLoadingAt),
|
readyForLoading: Boolean(operation.readyForLoadingAt),
|
||||||
loadedOnTrain: Boolean(operation.loadedOnTrainAt),
|
loadedOnTrain: Boolean(operation.loadedOnTrainAt),
|
||||||
@@ -1358,6 +1394,8 @@ export class TrainSchedulingService {
|
|||||||
},
|
},
|
||||||
documents: operation.documents ?? {},
|
documents: operation.documents ?? {},
|
||||||
gatepassGrantedAt: operation.gatepassGrantedAt ?? null,
|
gatepassGrantedAt: operation.gatepassGrantedAt ?? null,
|
||||||
|
gatepassSecuredAt: operation.gatepassGrantedAt ?? null,
|
||||||
|
gatepassStatus,
|
||||||
readyForLoadingAt: operation.readyForLoadingAt ?? null,
|
readyForLoadingAt: operation.readyForLoadingAt ?? null,
|
||||||
loadedOnTrainAt: operation.loadedOnTrainAt ?? null,
|
loadedOnTrainAt: operation.loadedOnTrainAt ?? null,
|
||||||
departedFromDjiboutiAt: operation.departedFromDjiboutiAt ?? null,
|
departedFromDjiboutiAt: operation.departedFromDjiboutiAt ?? null,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
||||||
import { Type } from 'class-transformer';
|
import { Type } from 'class-transformer';
|
||||||
import { ArrayNotEmpty, IsArray, IsIn, IsNumber, IsOptional, IsString, IsUUID, Min } from 'class-validator';
|
import { ArrayNotEmpty, IsArray, IsBoolean, IsIn, IsNumber, IsOptional, IsString, IsUUID, Min } from 'class-validator';
|
||||||
import { ValidateNested } from 'class-validator';
|
import { ValidateNested } from 'class-validator';
|
||||||
|
|
||||||
export class TruckEntranceDto {
|
export class TruckEntranceDto {
|
||||||
@@ -90,6 +90,11 @@ export class TruckEntranceDto {
|
|||||||
@Min(0)
|
@Min(0)
|
||||||
grossWeightKg?: number;
|
grossWeightKg?: number;
|
||||||
|
|
||||||
|
@ApiPropertyOptional({ description: 'Whether the customer truck was weighed at receipt.' })
|
||||||
|
@IsOptional()
|
||||||
|
@IsBoolean()
|
||||||
|
weighingRequired?: boolean;
|
||||||
|
|
||||||
@ApiPropertyOptional()
|
@ApiPropertyOptional()
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsNumber()
|
@IsNumber()
|
||||||
@@ -135,10 +140,11 @@ export class TruckEntranceDto {
|
|||||||
@IsString()
|
@IsString()
|
||||||
truckType?: string;
|
truckType?: string;
|
||||||
|
|
||||||
@ApiProperty()
|
@ApiPropertyOptional()
|
||||||
|
@IsOptional()
|
||||||
@IsNumber()
|
@IsNumber()
|
||||||
@Min(0)
|
@Min(0)
|
||||||
entranceTareWeightKg!: number;
|
entranceTareWeightKg?: number;
|
||||||
|
|
||||||
@ApiPropertyOptional()
|
@ApiPropertyOptional()
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
|
|||||||
@@ -1,8 +1,27 @@
|
|||||||
import { ApiProperty, ApiPropertyOptional, PartialType } from '@nestjs/swagger';
|
import { ApiProperty, ApiPropertyOptional, PartialType } from '@nestjs/swagger';
|
||||||
import { IsEnum, IsInt, IsNumber, IsOptional, IsString, IsUUID, Min } from 'class-validator';
|
import { Type } from 'class-transformer';
|
||||||
|
import { IsArray, IsEnum, IsInt, IsNumber, IsOptional, IsString, IsUUID, Min, ValidateNested } from 'class-validator';
|
||||||
|
|
||||||
import { FEE_RULE_TYPES, FeeRuleType } from '../entities/warehouse-fee-rule.entity';
|
import { FEE_RULE_TYPES, FeeRuleType } from '../entities/warehouse-fee-rule.entity';
|
||||||
|
|
||||||
|
export class FeeRuleTierDto {
|
||||||
|
@ApiProperty({ example: 4 })
|
||||||
|
@IsInt()
|
||||||
|
@Min(1)
|
||||||
|
fromDay!: number;
|
||||||
|
|
||||||
|
@ApiPropertyOptional({ example: 4, description: 'Inclusive. Leave empty for an open-ended tier.' })
|
||||||
|
@IsOptional()
|
||||||
|
@IsInt()
|
||||||
|
@Min(1)
|
||||||
|
toDay?: number | null;
|
||||||
|
|
||||||
|
@ApiProperty({ example: 2500 })
|
||||||
|
@IsNumber()
|
||||||
|
@Min(0)
|
||||||
|
ratePerDay!: number;
|
||||||
|
}
|
||||||
|
|
||||||
export class CreateFeeRuleDto {
|
export class CreateFeeRuleDto {
|
||||||
@ApiProperty()
|
@ApiProperty()
|
||||||
@IsString()
|
@IsString()
|
||||||
@@ -67,6 +86,13 @@ export class CreateFeeRuleDto {
|
|||||||
@Min(0)
|
@Min(0)
|
||||||
ratePerDay!: number;
|
ratePerDay!: number;
|
||||||
|
|
||||||
|
@ApiPropertyOptional({ type: [FeeRuleTierDto] })
|
||||||
|
@IsOptional()
|
||||||
|
@IsArray()
|
||||||
|
@ValidateNested({ each: true })
|
||||||
|
@Type(() => FeeRuleTierDto)
|
||||||
|
tiers?: FeeRuleTierDto[];
|
||||||
|
|
||||||
@ApiPropertyOptional({ default: 'USD' })
|
@ApiPropertyOptional({ default: 'USD' })
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsString()
|
@IsString()
|
||||||
|
|||||||
@@ -4,6 +4,12 @@ import { Column, Entity, Index } from 'typeorm';
|
|||||||
export const FEE_RULE_TYPES = ['STORAGE_FEE', 'DEMURRAGE_FEE'] as const;
|
export const FEE_RULE_TYPES = ['STORAGE_FEE', 'DEMURRAGE_FEE'] as const;
|
||||||
export type FeeRuleType = (typeof FEE_RULE_TYPES)[number];
|
export type FeeRuleType = (typeof FEE_RULE_TYPES)[number];
|
||||||
|
|
||||||
|
export interface WarehouseFeeTier {
|
||||||
|
fromDay: number;
|
||||||
|
toDay: number | null;
|
||||||
|
ratePerDay: number;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Batch 5 — configurable storage / demurrage fee rules (no invoice/payment here — that is Batch 6).
|
* Batch 5 — configurable storage / demurrage fee rules (no invoice/payment here — that is Batch 6).
|
||||||
* The most specific active rule (highest `specificity` then lowest `priority`) applies to an item.
|
* The most specific active rule (highest `specificity` then lowest `priority`) applies to an item.
|
||||||
@@ -54,6 +60,9 @@ export class WarehouseFeeRule extends BaseEntity {
|
|||||||
@Column({ name: 'rate_per_day', type: 'numeric', precision: 14, scale: 2, default: 0 })
|
@Column({ name: 'rate_per_day', type: 'numeric', precision: 14, scale: 2, default: 0 })
|
||||||
ratePerDay!: number;
|
ratePerDay!: number;
|
||||||
|
|
||||||
|
@Column({ name: 'tiers', type: 'jsonb', default: () => "'[]'" })
|
||||||
|
tiers!: WarehouseFeeTier[];
|
||||||
|
|
||||||
@Column({ name: 'currency', type: 'varchar', length: 8, default: 'USD' })
|
@Column({ name: 'currency', type: 'varchar', length: 8, default: 'USD' })
|
||||||
currency!: string;
|
currency!: string;
|
||||||
|
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ export interface ImportTrainItemRow {
|
|||||||
wagonNumber: string | null;
|
wagonNumber: string | null;
|
||||||
sequenceNo: number | null;
|
sequenceNo: number | null;
|
||||||
allocatedWeightTons: number | null;
|
allocatedWeightTons: number | null;
|
||||||
|
freightType: string | null;
|
||||||
containerNumber: string | null;
|
containerNumber: string | null;
|
||||||
cargoType: string | null;
|
cargoType: string | null;
|
||||||
weight: number | null;
|
weight: number | null;
|
||||||
@@ -274,6 +275,7 @@ export class SchedulingReadFacade {
|
|||||||
w.wagon_number AS "wagonNumber",
|
w.wagon_number AS "wagonNumber",
|
||||||
tsw.sequence_no AS "sequenceNo",
|
tsw.sequence_no AS "sequenceNo",
|
||||||
wba.allocated_weight_tons AS "allocatedWeightTons",
|
wba.allocated_weight_tons AS "allocatedWeightTons",
|
||||||
|
b.freight_type AS "freightType",
|
||||||
(SELECT c.container_number FROM freight.containers c
|
(SELECT c.container_number FROM freight.containers c
|
||||||
WHERE c.booking_id = b.id AND c.deleted_at IS NULL
|
WHERE c.booking_id = b.id AND c.deleted_at IS NULL
|
||||||
ORDER BY c.container_number LIMIT 1) AS "containerNumber",
|
ORDER BY c.container_number LIMIT 1) AS "containerNumber",
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
import { BadRequestException, Injectable, NotFoundException } from '@nestjs/common';
|
||||||
import { ExchangeService } from '@edr/api-common';
|
import { ExchangeService } from '@edr/api-common';
|
||||||
import { DataSource } from 'typeorm';
|
import { DataSource } from 'typeorm';
|
||||||
|
|
||||||
import { CreateFeeRuleDto, UpdateFeeRuleDto } from './dto/fee-rule.dto';
|
import { CreateFeeRuleDto, UpdateFeeRuleDto } from './dto/fee-rule.dto';
|
||||||
import { FeeRuleType, WarehouseFeeRule } from './entities/warehouse-fee-rule.entity';
|
import { FeeRuleType, WarehouseFeeRule, WarehouseFeeTier } from './entities/warehouse-fee-rule.entity';
|
||||||
import { WarehouseFeeRuleRepository } from './warehouse-fee-rule.repository';
|
import { WarehouseFeeRuleRepository } from './warehouse-fee-rule.repository';
|
||||||
|
|
||||||
interface ItemAttributes {
|
interface ItemAttributes {
|
||||||
@@ -39,6 +39,15 @@ export interface FeePreview {
|
|||||||
containerCount: number;
|
containerCount: number;
|
||||||
billableUnits: number;
|
billableUnits: number;
|
||||||
amount: number;
|
amount: number;
|
||||||
|
tiers: Array<{
|
||||||
|
fromDay: number;
|
||||||
|
toDay: number | null;
|
||||||
|
appliedFromDay: number;
|
||||||
|
appliedToDay: number;
|
||||||
|
days: number;
|
||||||
|
ratePerDay: number;
|
||||||
|
amount: number;
|
||||||
|
}>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const MS_PER_DAY = 24 * 60 * 60 * 1000;
|
const MS_PER_DAY = 24 * 60 * 60 * 1000;
|
||||||
@@ -57,11 +66,16 @@ export class WarehouseFeeService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
createRule(dto: CreateFeeRuleDto): Promise<WarehouseFeeRule> {
|
createRule(dto: CreateFeeRuleDto): Promise<WarehouseFeeRule> {
|
||||||
return this.feeRuleRepository.create({ isActive: true, priority: 100, currency: 'USD', ...dto });
|
return this.feeRuleRepository.create({
|
||||||
|
isActive: true,
|
||||||
|
priority: 100,
|
||||||
|
currency: 'USD',
|
||||||
|
...this.normalizeRuleInput(dto),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async updateRule(id: string, dto: UpdateFeeRuleDto): Promise<WarehouseFeeRule> {
|
async updateRule(id: string, dto: UpdateFeeRuleDto): Promise<WarehouseFeeRule> {
|
||||||
const updated = await this.feeRuleRepository.update(id, dto);
|
const updated = await this.feeRuleRepository.update(id, this.normalizeRuleInput(dto));
|
||||||
if (!updated) throw new NotFoundException(`Fee rule ${id} not found`);
|
if (!updated) throw new NotFoundException(`Fee rule ${id} not found`);
|
||||||
return updated;
|
return updated;
|
||||||
}
|
}
|
||||||
@@ -70,6 +84,40 @@ export class WarehouseFeeService {
|
|||||||
return this.feeRuleRepository.softDelete(id);
|
return this.feeRuleRepository.softDelete(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private normalizeRuleInput<T extends CreateFeeRuleDto | UpdateFeeRuleDto>(dto: T): T {
|
||||||
|
if (dto.tiers === undefined) return dto;
|
||||||
|
const tiers = (dto.tiers ?? [])
|
||||||
|
.map((tier) => ({
|
||||||
|
fromDay: Number(tier.fromDay),
|
||||||
|
toDay: tier.toDay == null ? null : Number(tier.toDay),
|
||||||
|
ratePerDay: Number(tier.ratePerDay),
|
||||||
|
}))
|
||||||
|
.filter((tier) => tier.fromDay > 0 || tier.toDay != null || tier.ratePerDay > 0);
|
||||||
|
|
||||||
|
for (const tier of tiers) {
|
||||||
|
if (!Number.isInteger(tier.fromDay) || tier.fromDay < 1) {
|
||||||
|
throw new BadRequestException('Fee tier from day must be a positive whole number.');
|
||||||
|
}
|
||||||
|
if (tier.toDay != null && (!Number.isInteger(tier.toDay) || tier.toDay < tier.fromDay)) {
|
||||||
|
throw new BadRequestException('Fee tier to day must be empty or greater than/equal to from day.');
|
||||||
|
}
|
||||||
|
if (!Number.isFinite(tier.ratePerDay) || tier.ratePerDay < 0) {
|
||||||
|
throw new BadRequestException('Fee tier rate per day must be zero or greater.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const sorted = [...tiers].sort((a, b) => a.fromDay - b.fromDay || (a.toDay ?? Infinity) - (b.toDay ?? Infinity));
|
||||||
|
for (let i = 1; i < sorted.length; i += 1) {
|
||||||
|
const prev = sorted[i - 1];
|
||||||
|
const current = sorted[i];
|
||||||
|
if (prev.toDay == null || current.fromDay <= prev.toDay) {
|
||||||
|
throw new BadRequestException('Fee tiers cannot overlap. Use separate from/to day ranges.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return { ...dto, tiers: sorted } as T;
|
||||||
|
}
|
||||||
|
|
||||||
private async loadItem(inventoryId: string): Promise<ItemAttributes> {
|
private async loadItem(inventoryId: string): Promise<ItemAttributes> {
|
||||||
const [row] = await this.dataSource.query(
|
const [row] = await this.dataSource.query(
|
||||||
`SELECT inv.arrived_at AS "arrivedAt",
|
`SELECT inv.arrived_at AS "arrivedAt",
|
||||||
@@ -82,16 +130,27 @@ export class WarehouseFeeService {
|
|||||||
w.facility_id AS "facilityId",
|
w.facility_id AS "facilityId",
|
||||||
b.freight_type AS "freightType",
|
b.freight_type AS "freightType",
|
||||||
b.trade_direction AS "tradeDirection",
|
b.trade_direction AS "tradeDirection",
|
||||||
cgt.code AS "cargoTypeCode",
|
COALESCE(cgt.code, booking_cgt.code) AS "cargoTypeCode",
|
||||||
ctt.code AS "containerTypeCode",
|
COALESCE(ctt.code, booking_ctt.code) AS "containerTypeCode",
|
||||||
COALESCE(container_lines.container_count, 0) AS "bookingContainerCount"
|
COALESCE(container_lines.container_count, 0) AS "bookingContainerCount"
|
||||||
FROM freight.warehouse_inventory inv
|
FROM freight.warehouse_inventory inv
|
||||||
LEFT JOIN freight.warehouses w ON w.id = inv.warehouse_id
|
LEFT JOIN freight.warehouses w ON w.id = inv.warehouse_id
|
||||||
LEFT JOIN freight.bookings b ON b.id = inv.booking_id
|
LEFT JOIN freight.bookings b ON b.id = inv.booking_id
|
||||||
LEFT JOIN freight.cargoes cg ON cg.id = inv.cargo_id
|
LEFT JOIN freight.cargoes cg ON cg.id = inv.cargo_id
|
||||||
LEFT JOIN freight.cargo_types cgt ON cgt.id = cg.cargo_type_id
|
LEFT JOIN freight.cargo_types cgt ON cgt.id = cg.cargo_type_id
|
||||||
|
LEFT JOIN freight.cargo_types booking_cgt ON booking_cgt.id = b.cargo_type_id
|
||||||
LEFT JOIN freight.containers ct ON ct.id = inv.container_id
|
LEFT JOIN freight.containers ct ON ct.id = inv.container_id
|
||||||
LEFT JOIN freight.container_types ctt ON ctt.id = ct.container_type_id
|
LEFT JOIN freight.container_types ctt ON ctt.id = ct.container_type_id
|
||||||
|
LEFT JOIN LATERAL (
|
||||||
|
SELECT bc.container_type_id
|
||||||
|
FROM freight.booking_container bc
|
||||||
|
WHERE bc.booking_id = inv.booking_id
|
||||||
|
AND bc.deleted_at IS NULL
|
||||||
|
AND bc.container_type_id IS NOT NULL
|
||||||
|
ORDER BY bc.created_at ASC
|
||||||
|
LIMIT 1
|
||||||
|
) booking_container_type ON true
|
||||||
|
LEFT JOIN freight.container_types booking_ctt ON booking_ctt.id = booking_container_type.container_type_id
|
||||||
LEFT JOIN LATERAL (
|
LEFT JOIN LATERAL (
|
||||||
SELECT COALESCE(SUM(bc.quantity), 0)::int AS container_count
|
SELECT COALESCE(SUM(bc.quantity), 0)::int AS container_count
|
||||||
FROM freight.booking_container bc
|
FROM freight.booking_container bc
|
||||||
@@ -108,16 +167,26 @@ export class WarehouseFeeService {
|
|||||||
private matchScore(rule: WarehouseFeeRule, item: ItemAttributes): number | null {
|
private matchScore(rule: WarehouseFeeRule, item: ItemAttributes): number | null {
|
||||||
// Returns specificity score (#matched non-null scope fields), or null if any constraint fails.
|
// Returns specificity score (#matched non-null scope fields), or null if any constraint fails.
|
||||||
let score = 0;
|
let score = 0;
|
||||||
const check = (ruleVal: string | null | undefined, itemVal: string | null) => {
|
const normalized = (value: string | null | undefined) => value?.trim().toUpperCase() || null;
|
||||||
if (ruleVal == null) return true;
|
const check = (
|
||||||
if (itemVal != null && ruleVal.toUpperCase() === itemVal.toUpperCase()) {
|
ruleVal: string | null | undefined,
|
||||||
|
itemVal: string | null,
|
||||||
|
opts: { allowBoth?: boolean } = {},
|
||||||
|
) => {
|
||||||
|
const ruleCode = normalized(ruleVal);
|
||||||
|
if (ruleCode == null || ruleCode === 'ANY' || ruleCode === 'ALL') return true;
|
||||||
|
if (opts.allowBoth && ruleCode === 'BOTH') {
|
||||||
|
score += 1;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (ruleCode === normalized(itemVal)) {
|
||||||
score += 1;
|
score += 1;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
if (!check(rule.freightType, item.freightType)) return null;
|
if (!check(rule.freightType, item.freightType)) return null;
|
||||||
if (!check(rule.tradeDirection, item.tradeDirection)) return null;
|
if (!check(rule.tradeDirection, item.tradeDirection, { allowBoth: true })) return null;
|
||||||
if (!check(rule.cargoTypeCode, item.cargoTypeCode)) return null;
|
if (!check(rule.cargoTypeCode, item.cargoTypeCode)) return null;
|
||||||
if (!check(rule.containerType, item.containerTypeCode)) return null;
|
if (!check(rule.containerType, item.containerTypeCode)) return null;
|
||||||
if (!check(rule.facilityId, item.facilityId)) return null;
|
if (!check(rule.facilityId, item.facilityId)) return null;
|
||||||
@@ -153,6 +222,60 @@ export class WarehouseFeeService {
|
|||||||
return Math.round(amount * rate * 100) / 100;
|
return Math.round(amount * rate * 100) / 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private calculateTieredAmount(
|
||||||
|
tiers: WarehouseFeeTier[] | null | undefined,
|
||||||
|
elapsedDays: number,
|
||||||
|
containerCount: number,
|
||||||
|
): {
|
||||||
|
sourceAmount: number;
|
||||||
|
billableUnits: number;
|
||||||
|
chargeableDays: number;
|
||||||
|
weightedRatePerDay: number;
|
||||||
|
tiers: FeePreview['tiers'];
|
||||||
|
} {
|
||||||
|
const sourceTiers = (tiers ?? [])
|
||||||
|
.map((tier) => ({
|
||||||
|
fromDay: Number(tier.fromDay),
|
||||||
|
toDay: tier.toDay == null ? null : Number(tier.toDay),
|
||||||
|
ratePerDay: Number(tier.ratePerDay),
|
||||||
|
}))
|
||||||
|
.filter((tier) => Number.isFinite(tier.fromDay) && tier.fromDay > 0 && Number.isFinite(tier.ratePerDay))
|
||||||
|
.sort((a, b) => a.fromDay - b.fromDay);
|
||||||
|
|
||||||
|
let sourceAmount = 0;
|
||||||
|
let tierDays = 0;
|
||||||
|
const appliedTiers: FeePreview['tiers'] = [];
|
||||||
|
|
||||||
|
for (const tier of sourceTiers) {
|
||||||
|
if (elapsedDays < tier.fromDay) continue;
|
||||||
|
const appliedFromDay = tier.fromDay;
|
||||||
|
const appliedToDay = Math.min(elapsedDays, tier.toDay ?? elapsedDays);
|
||||||
|
const days = Math.max(0, appliedToDay - appliedFromDay + 1);
|
||||||
|
if (days <= 0) continue;
|
||||||
|
|
||||||
|
const amount = Math.round(days * containerCount * tier.ratePerDay * 100) / 100;
|
||||||
|
sourceAmount += amount;
|
||||||
|
tierDays += days;
|
||||||
|
appliedTiers.push({
|
||||||
|
fromDay: tier.fromDay,
|
||||||
|
toDay: tier.toDay,
|
||||||
|
appliedFromDay,
|
||||||
|
appliedToDay,
|
||||||
|
days,
|
||||||
|
ratePerDay: tier.ratePerDay,
|
||||||
|
amount,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
sourceAmount: Math.round(sourceAmount * 100) / 100,
|
||||||
|
billableUnits: tierDays * containerCount,
|
||||||
|
chargeableDays: tierDays,
|
||||||
|
weightedRatePerDay: tierDays > 0 ? Math.round((sourceAmount / tierDays / containerCount) * 100) / 100 : 0,
|
||||||
|
tiers: appliedTiers,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
private async compute(
|
private async compute(
|
||||||
ruleType: FeeRuleType,
|
ruleType: FeeRuleType,
|
||||||
rule: WarehouseFeeRule | null,
|
rule: WarehouseFeeRule | null,
|
||||||
@@ -176,13 +299,25 @@ export class WarehouseFeeService {
|
|||||||
const elapsedDays = start
|
const elapsedDays = start
|
||||||
? Math.max(0, Math.ceil((new Date(endDate).getTime() - start.getTime()) / MS_PER_DAY))
|
? Math.max(0, Math.ceil((new Date(endDate).getTime() - start.getTime()) / MS_PER_DAY))
|
||||||
: 0;
|
: 0;
|
||||||
const chargeableDays = Math.max(0, elapsedDays - freeDays);
|
const tiered = this.calculateTieredAmount(rule?.tiers, elapsedDays, containerCount);
|
||||||
const billableUnits = chargeableDays * containerCount;
|
const hasTiers = Boolean(rule?.tiers?.length);
|
||||||
const sourceAmount = Math.round(billableUnits * ratePerDay * 100) / 100;
|
const chargeableDays = hasTiers ? tiered.chargeableDays : Math.max(0, elapsedDays - freeDays);
|
||||||
|
const billableUnits = hasTiers ? tiered.billableUnits : chargeableDays * containerCount;
|
||||||
|
const sourceAmount = hasTiers ? tiered.sourceAmount : Math.round(billableUnits * ratePerDay * 100) / 100;
|
||||||
const amount = ruleCurrency ? await this.convertAmount(sourceAmount, ruleCurrency, targetCurrency) : 0;
|
const amount = ruleCurrency ? await this.convertAmount(sourceAmount, ruleCurrency, targetCurrency) : 0;
|
||||||
|
const sourceRatePerDay = hasTiers ? tiered.weightedRatePerDay : ratePerDay;
|
||||||
const convertedRatePerDay = ruleCurrency
|
const convertedRatePerDay = ruleCurrency
|
||||||
? await this.convertAmount(ratePerDay, ruleCurrency, targetCurrency)
|
? await this.convertAmount(sourceRatePerDay, ruleCurrency, targetCurrency)
|
||||||
: 0;
|
: 0;
|
||||||
|
const convertedTiers = ruleCurrency
|
||||||
|
? await Promise.all(
|
||||||
|
tiered.tiers.map(async (tier) => ({
|
||||||
|
...tier,
|
||||||
|
ratePerDay: await this.convertAmount(tier.ratePerDay, ruleCurrency, targetCurrency),
|
||||||
|
amount: await this.convertAmount(tier.amount, ruleCurrency, targetCurrency),
|
||||||
|
})),
|
||||||
|
)
|
||||||
|
: [];
|
||||||
|
|
||||||
return {
|
return {
|
||||||
ruleType,
|
ruleType,
|
||||||
@@ -201,6 +336,7 @@ export class WarehouseFeeService {
|
|||||||
containerCount,
|
containerCount,
|
||||||
billableUnits,
|
billableUnits,
|
||||||
amount,
|
amount,
|
||||||
|
tiers: hasTiers ? convertedTiers : [],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -84,9 +84,11 @@ export class WarehouseInspectionService {
|
|||||||
`SELECT inv.booking_id AS "bookingId",
|
`SELECT inv.booking_id AS "bookingId",
|
||||||
b.reference AS "bookingReference",
|
b.reference AS "bookingReference",
|
||||||
b.trade_direction AS "tradeDirection",
|
b.trade_direction AS "tradeDirection",
|
||||||
b.last_mile_delivery_address AS "lastMileDeliveryAddress"
|
b.last_mile_delivery_address AS "lastMileDeliveryAddress",
|
||||||
|
COALESCE(st.includes_last_mile, false) AS "serviceIncludesLastMile"
|
||||||
FROM freight.warehouse_inventory inv
|
FROM freight.warehouse_inventory inv
|
||||||
LEFT JOIN freight.bookings b ON b.id = inv.booking_id
|
LEFT JOIN freight.bookings b ON b.id = inv.booking_id
|
||||||
|
LEFT JOIN freight.service_types st ON st.id = b.service_type_id
|
||||||
WHERE inv.id = $1 AND inv.deleted_at IS NULL
|
WHERE inv.id = $1 AND inv.deleted_at IS NULL
|
||||||
LIMIT 1`,
|
LIMIT 1`,
|
||||||
[inventoryId],
|
[inventoryId],
|
||||||
@@ -98,7 +100,10 @@ export class WarehouseInspectionService {
|
|||||||
readyForPickupAt: new Date(),
|
readyForPickupAt: new Date(),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (row.bookingReference && row.lastMileDeliveryAddress) {
|
const hasLastMile =
|
||||||
|
Boolean(row.lastMileDeliveryAddress?.trim?.()) || Boolean(row.serviceIncludesLastMile);
|
||||||
|
|
||||||
|
if (row.bookingReference && hasLastMile) {
|
||||||
await this.lastMileService.acceptBooking(row.bookingReference);
|
await this.lastMileService.acceptBooking(row.bookingReference);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -139,8 +139,18 @@ export class WarehouseInventoryController {
|
|||||||
|
|
||||||
@Post('import/auto-unload-arrived-bookings')
|
@Post('import/auto-unload-arrived-bookings')
|
||||||
@ApiOperation({ summary: 'Unload all eligible assigned bookings of an ARRIVED import train (→ UNLOADED)' })
|
@ApiOperation({ summary: 'Unload all eligible assigned bookings of an ARRIVED import train (→ UNLOADED)' })
|
||||||
autoUnloadArrivedBookings(@Body() dto: { scheduleId: string; performedBy?: string }) {
|
autoUnloadArrivedBookings(@Body() dto: {
|
||||||
return this.inventoryService.autoUnloadArrivedBookings(dto.scheduleId, dto.performedBy);
|
scheduleId: string;
|
||||||
|
warehouseId?: string;
|
||||||
|
performedBy?: string;
|
||||||
|
assignments?: { bookingId: string; warehouseId: string; yardId: string; zoneId: string }[];
|
||||||
|
}) {
|
||||||
|
return this.inventoryService.autoUnloadArrivedBookings(
|
||||||
|
dto.scheduleId,
|
||||||
|
dto.performedBy,
|
||||||
|
dto.warehouseId,
|
||||||
|
dto.assignments,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get('import/unloaded-queue')
|
@Get('import/unloaded-queue')
|
||||||
|
|||||||
@@ -180,6 +180,10 @@ interface LocationRef {
|
|||||||
zoneId: string;
|
zoneId: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface BookingUnloadLocation extends LocationRef {
|
||||||
|
bookingId: string;
|
||||||
|
}
|
||||||
|
|
||||||
interface LocationNode {
|
interface LocationNode {
|
||||||
capacityWeight?: number | null;
|
capacityWeight?: number | null;
|
||||||
capacityContainers?: number | null;
|
capacityContainers?: number | null;
|
||||||
@@ -221,6 +225,11 @@ export interface EligibleBookingRow {
|
|||||||
firstMileDriverPhone: string | null;
|
firstMileDriverPhone: string | null;
|
||||||
firstMileDriverLicenseNumber: string | null;
|
firstMileDriverLicenseNumber: string | null;
|
||||||
firstMileTruckType: string | null;
|
firstMileTruckType: string | null;
|
||||||
|
customerTruckPlateNumber: string | null;
|
||||||
|
customerTruckDriverName: string | null;
|
||||||
|
customerTruckType: string | null;
|
||||||
|
customerTruckContainerNumber: string | null;
|
||||||
|
customerTruckAssignedAt: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface BulkReceiveResult {
|
export interface BulkReceiveResult {
|
||||||
@@ -302,6 +311,11 @@ export interface ImportUnloadedRow {
|
|||||||
inspectionStatus: string | null;
|
inspectionStatus: string | null;
|
||||||
pickupOption: string;
|
pickupOption: string;
|
||||||
lastMileRequested: boolean;
|
lastMileRequested: boolean;
|
||||||
|
customerTruckPlateNumber: string | null;
|
||||||
|
customerTruckDriverName: string | null;
|
||||||
|
customerTruckType: string | null;
|
||||||
|
customerTruckContainerNumber: string | null;
|
||||||
|
customerTruckAssignedAt: string | null;
|
||||||
currentStatus: string;
|
currentStatus: string;
|
||||||
releaseDate: string | null;
|
releaseDate: string | null;
|
||||||
releaseOrderReference: string | null;
|
releaseOrderReference: string | null;
|
||||||
@@ -504,8 +518,9 @@ export class WarehouseInventoryService {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** First warehouse that has at least one yard + zone (fallback location for auto-unload). */
|
/** First matching warehouse that has at least one yard + zone (fallback location for auto-unload). */
|
||||||
private async pickDefaultLocation(): Promise<DefaultLocation | null> {
|
private async pickDefaultLocation(warehouseId?: string): Promise<DefaultLocation | null> {
|
||||||
|
const params = warehouseId ? [warehouseId] : [];
|
||||||
const [row]: DefaultLocation[] = await this.dataSource.query(
|
const [row]: DefaultLocation[] = await this.dataSource.query(
|
||||||
`SELECT wh.id AS "warehouseId", wh.facility_id AS "facilityId",
|
`SELECT wh.id AS "warehouseId", wh.facility_id AS "facilityId",
|
||||||
yard.id AS "yardId", zone.id AS "zoneId"
|
yard.id AS "yardId", zone.id AS "zoneId"
|
||||||
@@ -513,8 +528,10 @@ export class WarehouseInventoryService {
|
|||||||
JOIN freight.warehouse_yards yard ON yard.warehouse_id = wh.id AND yard.deleted_at IS NULL
|
JOIN freight.warehouse_yards yard ON yard.warehouse_id = wh.id AND yard.deleted_at IS NULL
|
||||||
JOIN freight.warehouse_zones zone ON zone.yard_id = yard.id AND zone.deleted_at IS NULL
|
JOIN freight.warehouse_zones zone ON zone.yard_id = yard.id AND zone.deleted_at IS NULL
|
||||||
WHERE wh.deleted_at IS NULL
|
WHERE wh.deleted_at IS NULL
|
||||||
|
${warehouseId ? 'AND wh.id = $1' : ''}
|
||||||
ORDER BY wh.created_at ASC
|
ORDER BY wh.created_at ASC
|
||||||
LIMIT 1`,
|
LIMIT 1`,
|
||||||
|
params,
|
||||||
);
|
);
|
||||||
return row ?? null;
|
return row ?? null;
|
||||||
}
|
}
|
||||||
@@ -592,6 +609,7 @@ export class WarehouseInventoryService {
|
|||||||
dto.warehouseId && dto.yardId && dto.zoneId
|
dto.warehouseId && dto.yardId && dto.zoneId
|
||||||
? { warehouseId: dto.warehouseId, yardId: dto.yardId, zoneId: dto.zoneId, facilityId: dto.facilityId ?? null }
|
? { warehouseId: dto.warehouseId, yardId: dto.yardId, zoneId: dto.zoneId, facilityId: dto.facilityId ?? null }
|
||||||
: null;
|
: null;
|
||||||
|
if (!location && dto.warehouseId) location = await this.pickDefaultLocation(dto.warehouseId);
|
||||||
if (!location) location = await this.pickDefaultLocation();
|
if (!location) location = await this.pickDefaultLocation();
|
||||||
if (!location) {
|
if (!location) {
|
||||||
throw new BadRequestException('No warehouse/yard/zone provided or configured for unloading');
|
throw new BadRequestException('No warehouse/yard/zone provided or configured for unloading');
|
||||||
@@ -704,7 +722,12 @@ export class WarehouseInventoryService {
|
|||||||
) AS "firstMileDriverName",
|
) AS "firstMileDriverName",
|
||||||
driver.phone_number AS "firstMileDriverPhone",
|
driver.phone_number AS "firstMileDriverPhone",
|
||||||
driver.license_number AS "firstMileDriverLicenseNumber",
|
driver.license_number AS "firstMileDriverLicenseNumber",
|
||||||
v.vehicle_type AS "firstMileTruckType"
|
v.vehicle_type AS "firstMileTruckType",
|
||||||
|
b.customer_truck_plate_number AS "customerTruckPlateNumber",
|
||||||
|
b.customer_truck_driver_name AS "customerTruckDriverName",
|
||||||
|
b.customer_truck_type AS "customerTruckType",
|
||||||
|
b.customer_truck_container_number AS "customerTruckContainerNumber",
|
||||||
|
b.customer_truck_assigned_at AS "customerTruckAssignedAt"
|
||||||
FROM freight.bookings b
|
FROM freight.bookings b
|
||||||
LEFT JOIN freight.companies company ON company.id = b.company_id
|
LEFT JOIN freight.companies company ON company.id = b.company_id
|
||||||
LEFT JOIN freight.yards oy ON oy.id = b.origin_yard_id
|
LEFT JOIN freight.yards oy ON oy.id = b.origin_yard_id
|
||||||
@@ -796,7 +819,12 @@ export class WarehouseInventoryService {
|
|||||||
) AS "firstMileDriverName",
|
) AS "firstMileDriverName",
|
||||||
driver.phone_number AS "firstMileDriverPhone",
|
driver.phone_number AS "firstMileDriverPhone",
|
||||||
driver.license_number AS "firstMileDriverLicenseNumber",
|
driver.license_number AS "firstMileDriverLicenseNumber",
|
||||||
v.vehicle_type AS "firstMileTruckType"
|
v.vehicle_type AS "firstMileTruckType",
|
||||||
|
b.customer_truck_plate_number AS "customerTruckPlateNumber",
|
||||||
|
b.customer_truck_driver_name AS "customerTruckDriverName",
|
||||||
|
b.customer_truck_type AS "customerTruckType",
|
||||||
|
b.customer_truck_container_number AS "customerTruckContainerNumber",
|
||||||
|
b.customer_truck_assigned_at AS "customerTruckAssignedAt"
|
||||||
FROM freight.bookings b
|
FROM freight.bookings b
|
||||||
LEFT JOIN freight.companies company ON company.id = b.company_id
|
LEFT JOIN freight.companies company ON company.id = b.company_id
|
||||||
LEFT JOIN freight.yards oy ON oy.id = b.origin_yard_id
|
LEFT JOIN freight.yards oy ON oy.id = b.origin_yard_id
|
||||||
@@ -1041,9 +1069,16 @@ export class WarehouseInventoryService {
|
|||||||
COALESCE(inv.grn_number, substring(inv.notes FROM 'GRN Number: ([^\\n\\r]+)')) AS "grnNumber",
|
COALESCE(inv.grn_number, substring(inv.notes FROM 'GRN Number: ([^\\n\\r]+)')) AS "grnNumber",
|
||||||
ts.train_number AS "trainSchedule",
|
ts.train_number AS "trainSchedule",
|
||||||
inv.inspection_status AS "inspectionStatus",
|
inv.inspection_status AS "inspectionStatus",
|
||||||
CASE WHEN b.last_mile_delivery_address IS NOT NULL
|
CASE WHEN NULLIF(TRIM(COALESCE(b.last_mile_delivery_address, '')), '') IS NOT NULL
|
||||||
|
OR COALESCE(st.includes_last_mile, false)
|
||||||
THEN 'DOOR_DELIVERY' ELSE 'TERMINAL_PICKUP' END AS "pickupOption",
|
THEN 'DOOR_DELIVERY' ELSE 'TERMINAL_PICKUP' END AS "pickupOption",
|
||||||
(b.last_mile_delivery_address IS NOT NULL) AS "lastMileRequested",
|
(NULLIF(TRIM(COALESCE(b.last_mile_delivery_address, '')), '') IS NOT NULL
|
||||||
|
OR COALESCE(st.includes_last_mile, false)) AS "lastMileRequested",
|
||||||
|
b.customer_truck_plate_number AS "customerTruckPlateNumber",
|
||||||
|
b.customer_truck_driver_name AS "customerTruckDriverName",
|
||||||
|
b.customer_truck_type AS "customerTruckType",
|
||||||
|
b.customer_truck_container_number AS "customerTruckContainerNumber",
|
||||||
|
b.customer_truck_assigned_at AS "customerTruckAssignedAt",
|
||||||
inv.status AS "currentStatus",
|
inv.status AS "currentStatus",
|
||||||
inv.release_date AS "releaseDate",
|
inv.release_date AS "releaseDate",
|
||||||
inv.release_order_reference AS "releaseOrderReference",
|
inv.release_order_reference AS "releaseOrderReference",
|
||||||
@@ -1056,6 +1091,7 @@ export class WarehouseInventoryService {
|
|||||||
LEFT JOIN freight.bookings b ON b.id = inv.booking_id AND b.deleted_at IS NULL
|
LEFT JOIN freight.bookings b ON b.id = inv.booking_id AND b.deleted_at IS NULL
|
||||||
LEFT JOIN freight.companies company ON company.id = b.company_id
|
LEFT JOIN freight.companies company ON company.id = b.company_id
|
||||||
LEFT JOIN freight.cargo_types cgt ON cgt.id = b.cargo_type_id
|
LEFT JOIN freight.cargo_types cgt ON cgt.id = b.cargo_type_id
|
||||||
|
LEFT JOIN freight.service_types st ON st.id = b.service_type_id
|
||||||
LEFT JOIN freight.yards oy ON oy.id = b.origin_yard_id
|
LEFT JOIN freight.yards oy ON oy.id = b.origin_yard_id
|
||||||
LEFT JOIN freight.yards dy ON dy.id = b.destination_yard_id
|
LEFT JOIN freight.yards dy ON dy.id = b.destination_yard_id
|
||||||
LEFT JOIN freight.train_schedule_bookings tsb ON tsb.booking_id = b.id AND tsb.deleted_at IS NULL
|
LEFT JOIN freight.train_schedule_bookings tsb ON tsb.booking_id = b.id AND tsb.deleted_at IS NULL
|
||||||
@@ -1157,6 +1193,8 @@ export class WarehouseInventoryService {
|
|||||||
async autoUnloadArrivedBookings(
|
async autoUnloadArrivedBookings(
|
||||||
scheduleId: string,
|
scheduleId: string,
|
||||||
performedBy?: string,
|
performedBy?: string,
|
||||||
|
warehouseId?: string,
|
||||||
|
assignments: BookingUnloadLocation[] = [],
|
||||||
): Promise<AutoUnloadArrivedResult> {
|
): Promise<AutoUnloadArrivedResult> {
|
||||||
const result: AutoUnloadArrivedResult = { unloadedCount: 0, skippedCount: 0, failedCount: 0, results: [] };
|
const result: AutoUnloadArrivedResult = { unloadedCount: 0, skippedCount: 0, failedCount: 0, results: [] };
|
||||||
|
|
||||||
@@ -1203,7 +1241,21 @@ export class WarehouseInventoryService {
|
|||||||
[scheduleId],
|
[scheduleId],
|
||||||
);
|
);
|
||||||
|
|
||||||
const fallback = await this.pickDefaultLocation();
|
const requestedLocation = warehouseId ? await this.pickDefaultLocation(warehouseId) : null;
|
||||||
|
if (warehouseId && !requestedLocation) {
|
||||||
|
throw new BadRequestException('Selected warehouse has no yard/zone configured for unloading');
|
||||||
|
}
|
||||||
|
const fallback = requestedLocation ?? (await this.pickDefaultLocation());
|
||||||
|
const assignmentByBooking = new Map(
|
||||||
|
assignments.map((assignment) => [
|
||||||
|
assignment.bookingId,
|
||||||
|
{
|
||||||
|
warehouseId: assignment.warehouseId,
|
||||||
|
yardId: assignment.yardId,
|
||||||
|
zoneId: assignment.zoneId,
|
||||||
|
} satisfies LocationRef,
|
||||||
|
]),
|
||||||
|
);
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
|
|
||||||
for (const booking of bookings) {
|
for (const booking of bookings) {
|
||||||
@@ -1223,6 +1275,8 @@ export class WarehouseInventoryService {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const existing = (await this.inventoryRepository.findAll({ where: { bookingId: booking.id } }))[0];
|
const existing = (await this.inventoryRepository.findAll({ where: { bookingId: booking.id } }))[0];
|
||||||
|
const assignedLocation = assignmentByBooking.get(booking.id) ?? null;
|
||||||
|
const unloadLocation = assignedLocation ?? requestedLocation;
|
||||||
|
|
||||||
// Already unloaded or further along — leave it (do not regress the lifecycle).
|
// Already unloaded or further along — leave it (do not regress the lifecycle).
|
||||||
if (existing && existing.status !== 'RECEIVED') {
|
if (existing && existing.status !== 'RECEIVED') {
|
||||||
@@ -1232,6 +1286,13 @@ export class WarehouseInventoryService {
|
|||||||
|
|
||||||
if (existing) {
|
if (existing) {
|
||||||
await this.inventoryRepository.update(existing.id, {
|
await this.inventoryRepository.update(existing.id, {
|
||||||
|
...(unloadLocation
|
||||||
|
? {
|
||||||
|
warehouseId: unloadLocation.warehouseId,
|
||||||
|
yardId: unloadLocation.yardId,
|
||||||
|
zoneId: unloadLocation.zoneId,
|
||||||
|
}
|
||||||
|
: {}),
|
||||||
status: 'UNLOADED',
|
status: 'UNLOADED',
|
||||||
unloadedAt: now,
|
unloadedAt: now,
|
||||||
arrivedAt: existing.arrivedAt ?? now,
|
arrivedAt: existing.arrivedAt ?? now,
|
||||||
@@ -1239,7 +1300,7 @@ export class WarehouseInventoryService {
|
|||||||
await this.activityLog.record({
|
await this.activityLog.record({
|
||||||
activityType: 'INVENTORY_UNLOADED',
|
activityType: 'INVENTORY_UNLOADED',
|
||||||
inventoryId: existing.id,
|
inventoryId: existing.id,
|
||||||
warehouseId: existing.warehouseId,
|
warehouseId: unloadLocation?.warehouseId ?? existing.warehouseId,
|
||||||
description: 'Unloaded from arrived import train',
|
description: 'Unloaded from arrived import train',
|
||||||
performedBy,
|
performedBy,
|
||||||
});
|
});
|
||||||
@@ -1254,7 +1315,7 @@ export class WarehouseInventoryService {
|
|||||||
tradeDirection: booking.tradeDirection,
|
tradeDirection: booking.tradeDirection,
|
||||||
cargoTypeCode: booking.cargoTypeCode,
|
cargoTypeCode: booking.cargoTypeCode,
|
||||||
});
|
});
|
||||||
const location = allocated ?? fallback;
|
const location = assignedLocation ?? requestedLocation ?? allocated ?? fallback;
|
||||||
if (!location) {
|
if (!location) {
|
||||||
fail('No warehouse/yard/zone configured');
|
fail('No warehouse/yard/zone configured');
|
||||||
continue;
|
continue;
|
||||||
@@ -1336,6 +1397,16 @@ export class WarehouseInventoryService {
|
|||||||
if (!['ARRIVED', 'ARRIVED_AT_DJIBOUTI'].includes(schedule.status)) {
|
if (!['ARRIVED', 'ARRIVED_AT_DJIBOUTI'].includes(schedule.status)) {
|
||||||
throw new BadRequestException(`Train schedule is ${schedule.status}, not ARRIVED`);
|
throw new BadRequestException(`Train schedule is ${schedule.status}, not ARRIVED`);
|
||||||
}
|
}
|
||||||
|
const [gatepass] = await this.dataSource.query(
|
||||||
|
`SELECT gatepass_granted_at AS "gatepassSecuredAt"
|
||||||
|
FROM freight.import_djibouti_operations
|
||||||
|
WHERE train_schedule_id = $1 AND deleted_at IS NULL
|
||||||
|
LIMIT 1`,
|
||||||
|
[scheduleId],
|
||||||
|
);
|
||||||
|
if (!gatepass?.gatepassSecuredAt) {
|
||||||
|
throw new BadRequestException('Djibouti Port entry blocked: gate pass status is NOT_SECURED');
|
||||||
|
}
|
||||||
|
|
||||||
const items: Array<{
|
const items: Array<{
|
||||||
bookingId: string;
|
bookingId: string;
|
||||||
@@ -1631,13 +1702,17 @@ export class WarehouseInventoryService {
|
|||||||
if (!bookingId) return;
|
if (!bookingId) return;
|
||||||
const [booking] = await this.dataSource.query(
|
const [booking] = await this.dataSource.query(
|
||||||
`SELECT reference,
|
`SELECT reference,
|
||||||
last_mile_delivery_address AS "lastMileDeliveryAddress"
|
last_mile_delivery_address AS "lastMileDeliveryAddress",
|
||||||
FROM freight.bookings
|
COALESCE(st.includes_last_mile, false) AS "serviceIncludesLastMile"
|
||||||
WHERE id = $1 AND deleted_at IS NULL
|
FROM freight.bookings b
|
||||||
|
LEFT JOIN freight.service_types st ON st.id = b.service_type_id
|
||||||
|
WHERE b.id = $1 AND b.deleted_at IS NULL
|
||||||
LIMIT 1`,
|
LIMIT 1`,
|
||||||
[bookingId],
|
[bookingId],
|
||||||
);
|
);
|
||||||
if (!booking?.reference || !booking.lastMileDeliveryAddress) return;
|
const hasLastMile =
|
||||||
|
Boolean(booking?.lastMileDeliveryAddress?.trim?.()) || Boolean(booking?.serviceIncludesLastMile);
|
||||||
|
if (!booking?.reference || !hasLastMile) return;
|
||||||
await this.lastMileService.acceptBooking(booking.reference);
|
await this.lastMileService.acceptBooking(booking.reference);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1955,11 +2030,19 @@ export class WarehouseInventoryService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const isTruckLeaving = dto.grossWeight !== undefined && Boolean(dto.gateOutTime);
|
const isTruckLeaving = dto.grossWeight !== undefined && Boolean(dto.gateOutTime);
|
||||||
|
if (isTruckLeaving) {
|
||||||
|
await this.invoices.assertClearanceAllowed(id);
|
||||||
|
}
|
||||||
const releaseDate = isTruckLeaving
|
const releaseDate = isTruckLeaving
|
||||||
? dto.releaseDate ? new Date(dto.releaseDate) : new Date()
|
? dto.releaseDate ? new Date(dto.releaseDate) : new Date()
|
||||||
: item.releaseDate ?? null;
|
: item.releaseDate ?? null;
|
||||||
const reference = dto.reference?.trim() || (await this.generateReleaseReference(item));
|
const reference = isTruckLeaving
|
||||||
const exitInspectionNote = this.buildExitInspectionNote(dto);
|
? item.releaseOrderReference || dto.reference?.trim() || (await this.generateReleaseReference(item))
|
||||||
|
: dto.reference?.trim() || (await this.generateReleaseReference(item));
|
||||||
|
const exitInspectionDto = isTruckLeaving
|
||||||
|
? this.preserveTruckArrivalForExit(dto, item.notes)
|
||||||
|
: dto;
|
||||||
|
const exitInspectionNote = this.buildExitInspectionNote(exitInspectionDto);
|
||||||
|
|
||||||
await this.dataSource.transaction(async (manager) => {
|
await this.dataSource.transaction(async (manager) => {
|
||||||
await manager.getRepository(WarehouseInventory).update(id, {
|
await manager.getRepository(WarehouseInventory).update(id, {
|
||||||
@@ -1967,6 +2050,17 @@ export class WarehouseInventoryService {
|
|||||||
releaseOrderReference: reference,
|
releaseOrderReference: reference,
|
||||||
notes: this.replaceExitInspectionNote(item.notes, exitInspectionNote),
|
notes: this.replaceExitInspectionNote(item.notes, exitInspectionNote),
|
||||||
});
|
});
|
||||||
|
if (!isTruckLeaving && item.bookingId) {
|
||||||
|
await manager.query(
|
||||||
|
`UPDATE freight.bookings
|
||||||
|
SET customer_truck_arrived_at = COALESCE(customer_truck_arrived_at, NOW()),
|
||||||
|
updated_at = NOW()
|
||||||
|
WHERE id = $1
|
||||||
|
AND customer_truck_assigned_at IS NOT NULL
|
||||||
|
AND deleted_at IS NULL`,
|
||||||
|
[item.bookingId],
|
||||||
|
);
|
||||||
|
}
|
||||||
await this.activityLog.record(
|
await this.activityLog.record(
|
||||||
{
|
{
|
||||||
activityType: 'INVENTORY_RELEASED',
|
activityType: 'INVENTORY_RELEASED',
|
||||||
@@ -2034,6 +2128,7 @@ export class WarehouseInventoryService {
|
|||||||
if (!row.releaseDate) {
|
if (!row.releaseDate) {
|
||||||
throw new BadRequestException('A release order must be issued before downloading the exit paper');
|
throw new BadRequestException('A release order must be issued before downloading the exit paper');
|
||||||
}
|
}
|
||||||
|
await this.invoices.assertClearanceAllowed(id);
|
||||||
|
|
||||||
const bookingReference = row?.bookingReference || 'N/A';
|
const bookingReference = row?.bookingReference || 'N/A';
|
||||||
const reference =
|
const reference =
|
||||||
@@ -2180,11 +2275,19 @@ export class WarehouseInventoryService {
|
|||||||
throw new BadRequestException('Please save your signature before approving delivery');
|
throw new BadRequestException('Please save your signature before approving delivery');
|
||||||
}
|
}
|
||||||
|
|
||||||
const [item]: Array<{ id: string; warehouseId: string | null; notes: string | null }> =
|
const [item]: Array<{
|
||||||
|
id: string;
|
||||||
|
warehouseId: string | null;
|
||||||
|
notes: string | null;
|
||||||
|
customerTruckAssignedAt: string | null;
|
||||||
|
customerTruckArrivedAt: string | null;
|
||||||
|
}> =
|
||||||
await this.dataSource.query(
|
await this.dataSource.query(
|
||||||
`SELECT inv.id,
|
`SELECT inv.id,
|
||||||
inv.warehouse_id AS "warehouseId",
|
inv.warehouse_id AS "warehouseId",
|
||||||
inv.notes
|
inv.notes,
|
||||||
|
b.customer_truck_assigned_at AS "customerTruckAssignedAt",
|
||||||
|
b.customer_truck_arrived_at AS "customerTruckArrivedAt"
|
||||||
FROM freight.warehouse_inventory inv
|
FROM freight.warehouse_inventory inv
|
||||||
JOIN freight.bookings b ON b.id = inv.booking_id AND b.deleted_at IS NULL
|
JOIN freight.bookings b ON b.id = inv.booking_id AND b.deleted_at IS NULL
|
||||||
WHERE inv.booking_id = $1
|
WHERE inv.booking_id = $1
|
||||||
@@ -2198,6 +2301,10 @@ export class WarehouseInventoryService {
|
|||||||
if (!item) {
|
if (!item) {
|
||||||
throw new BadRequestException('Delivery can be approved after warehouse inspection has passed');
|
throw new BadRequestException('Delivery can be approved after warehouse inspection has passed');
|
||||||
}
|
}
|
||||||
|
if (item.customerTruckAssignedAt && !item.customerTruckArrivedAt) {
|
||||||
|
throw new BadRequestException('Customer truck arrival must be recorded before delivery approval');
|
||||||
|
}
|
||||||
|
await this.invoices.assertClearanceAllowed(item.id);
|
||||||
|
|
||||||
const approvedAt = new Date();
|
const approvedAt = new Date();
|
||||||
const approval = {
|
const approval = {
|
||||||
@@ -2301,6 +2408,7 @@ export class WarehouseInventoryService {
|
|||||||
if (!row) {
|
if (!row) {
|
||||||
throw new NotFoundException(`Inventory item ${id} not found`);
|
throw new NotFoundException(`Inventory item ${id} not found`);
|
||||||
}
|
}
|
||||||
|
await this.invoices.assertClearanceAllowed(id);
|
||||||
if (row.inspectionStatus !== 'PASSED') {
|
if (row.inspectionStatus !== 'PASSED') {
|
||||||
throw new BadRequestException('Handover document is available after inspection has passed');
|
throw new BadRequestException('Handover document is available after inspection has passed');
|
||||||
}
|
}
|
||||||
@@ -3302,8 +3410,13 @@ export class WarehouseInventoryService {
|
|||||||
if (!truckEntrance.driverPhone?.trim()) {
|
if (!truckEntrance.driverPhone?.trim()) {
|
||||||
throw new BadRequestException('Driver phone is required for entrance registration');
|
throw new BadRequestException('Driver phone is required for entrance registration');
|
||||||
}
|
}
|
||||||
if (truckEntrance.entranceTareWeightKg === undefined || Number(truckEntrance.entranceTareWeightKg) < 0) {
|
if (truckEntrance.weighingRequired) {
|
||||||
throw new BadRequestException('Entrance tare weight is required for entrance registration');
|
if (truckEntrance.grossWeightKg === undefined || Number(truckEntrance.grossWeightKg) < 0) {
|
||||||
|
throw new BadRequestException('Gross weight is required when customer truck weighing is Yes');
|
||||||
|
}
|
||||||
|
if (truckEntrance.exitTareWeightKg === undefined || Number(truckEntrance.exitTareWeightKg) < 0) {
|
||||||
|
throw new BadRequestException('Exit tare weight is required when customer truck weighing is Yes');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3325,6 +3438,11 @@ export class WarehouseInventoryService {
|
|||||||
firstMileDriverPhone?: string | null;
|
firstMileDriverPhone?: string | null;
|
||||||
firstMileDriverLicenseNumber?: string | null;
|
firstMileDriverLicenseNumber?: string | null;
|
||||||
firstMileTruckType?: string | null;
|
firstMileTruckType?: string | null;
|
||||||
|
customerTruckPlateNumber?: string | null;
|
||||||
|
customerTruckDriverName?: string | null;
|
||||||
|
customerTruckType?: string | null;
|
||||||
|
customerTruckContainerNumber?: string | null;
|
||||||
|
customerTruckAssignedAt?: string | null;
|
||||||
},
|
},
|
||||||
): TruckEntranceDto {
|
): TruckEntranceDto {
|
||||||
return {
|
return {
|
||||||
@@ -3340,16 +3458,22 @@ export class WarehouseInventoryService {
|
|||||||
booking.containerQuantity !== undefined && booking.containerQuantity !== null
|
booking.containerQuantity !== undefined && booking.containerQuantity !== null
|
||||||
? Number(booking.containerQuantity)
|
? Number(booking.containerQuantity)
|
||||||
: submitted.unitCount,
|
: submitted.unitCount,
|
||||||
grossWeightKg:
|
grossWeightKg: submitted.grossWeightKg,
|
||||||
booking.weight !== undefined && booking.weight !== null
|
truckPlateNumber:
|
||||||
? Number(booking.weight)
|
booking.firstMileTruckPlateNumber?.trim() ||
|
||||||
: submitted.grossWeightKg,
|
booking.customerTruckPlateNumber?.trim() ||
|
||||||
truckPlateNumber: booking.firstMileTruckPlateNumber?.trim() || submitted.truckPlateNumber,
|
submitted.truckPlateNumber,
|
||||||
trailerPlateNumber: booking.firstMileTrailerPlateNumber?.trim() || submitted.trailerPlateNumber,
|
trailerPlateNumber: booking.firstMileTrailerPlateNumber?.trim() || submitted.trailerPlateNumber,
|
||||||
driverName: booking.firstMileDriverName?.trim() || submitted.driverName,
|
driverName:
|
||||||
|
booking.firstMileDriverName?.trim() ||
|
||||||
|
booking.customerTruckDriverName?.trim() ||
|
||||||
|
submitted.driverName,
|
||||||
driverPhone: booking.firstMileDriverPhone?.trim() || submitted.driverPhone,
|
driverPhone: booking.firstMileDriverPhone?.trim() || submitted.driverPhone,
|
||||||
driverLicenseNumber: booking.firstMileDriverLicenseNumber?.trim() || submitted.driverLicenseNumber,
|
driverLicenseNumber: booking.firstMileDriverLicenseNumber?.trim() || submitted.driverLicenseNumber,
|
||||||
truckType: booking.firstMileTruckType?.trim() || submitted.truckType,
|
truckType:
|
||||||
|
booking.firstMileTruckType?.trim() ||
|
||||||
|
booking.customerTruckType?.trim() ||
|
||||||
|
submitted.truckType,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3543,6 +3667,24 @@ export class WarehouseInventoryService {
|
|||||||
return rows.filter(Boolean).join('\n');
|
return rows.filter(Boolean).join('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private preserveTruckArrivalForExit(dto: ReleaseOrderDto, notes: string | null | undefined): ReleaseOrderDto {
|
||||||
|
const inspection = this.extractExitInspectionNote(notes);
|
||||||
|
if (!inspection) return dto;
|
||||||
|
|
||||||
|
return {
|
||||||
|
...dto,
|
||||||
|
truckPlateNumber: this.extractExitInspectionLine(inspection, 'Truck Plate') || dto.truckPlateNumber,
|
||||||
|
trailerPlateNumber: this.extractExitInspectionLine(inspection, 'Trailer Plate') || dto.trailerPlateNumber,
|
||||||
|
driverName: this.extractExitInspectionLine(inspection, 'Driver') || dto.driverName,
|
||||||
|
driverLicense: this.extractExitInspectionLine(inspection, 'Driver License') || dto.driverLicense,
|
||||||
|
driverPhone: this.extractExitInspectionLine(inspection, 'Driver Phone') || dto.driverPhone,
|
||||||
|
truckType: this.extractExitInspectionLine(inspection, 'Truck Type') || dto.truckType,
|
||||||
|
containerNumber: this.extractExitInspectionLine(inspection, 'Container Number') || dto.containerNumber,
|
||||||
|
gateInTime: this.extractExitInspectionLine(inspection, 'Gate In Time') || dto.gateInTime,
|
||||||
|
tareWeight: this.extractExitInspectionNumber(inspection, 'Tare Weight') ?? dto.tareWeight,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
private replaceExitInspectionNote(notes: string | null | undefined, exitInspectionNote: string | null): string | null {
|
private replaceExitInspectionNote(notes: string | null | undefined, exitInspectionNote: string | null): string | null {
|
||||||
const trimmed = notes?.trim();
|
const trimmed = notes?.trim();
|
||||||
if (!exitInspectionNote) return trimmed || null;
|
if (!exitInspectionNote) return trimmed || null;
|
||||||
@@ -3564,6 +3706,18 @@ export class WarehouseInventoryService {
|
|||||||
return notes.slice(index + marker.length).trim() || null;
|
return notes.slice(index + marker.length).trim() || null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private extractExitInspectionLine(note: string | null | undefined, label: string): string | null {
|
||||||
|
const match = note?.match(new RegExp(`^${label}:\\s*(.+)$`, 'im'));
|
||||||
|
return match?.[1]?.trim() || null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private extractExitInspectionNumber(note: string | null | undefined, label: string): number | undefined {
|
||||||
|
const value = this.extractExitInspectionLine(note, label)?.replace(/\s*kg$/i, '');
|
||||||
|
if (!value) return undefined;
|
||||||
|
const parsed = Number(value);
|
||||||
|
return Number.isFinite(parsed) ? parsed : undefined;
|
||||||
|
}
|
||||||
|
|
||||||
private extractReceiveSummary(notes?: string | null): string | null {
|
private extractReceiveSummary(notes?: string | null): string | null {
|
||||||
if (!notes?.trim()) return null;
|
if (!notes?.trim()) return null;
|
||||||
const withoutExit = notes.split('\n\n[Exit Inspection]')[0] ?? notes;
|
const withoutExit = notes.split('\n\n[Exit Inspection]')[0] ?? notes;
|
||||||
@@ -3622,6 +3776,7 @@ export class WarehouseInventoryService {
|
|||||||
truck?.driverPhone ? `Driver Phone: ${truck.driverPhone}` : null,
|
truck?.driverPhone ? `Driver Phone: ${truck.driverPhone}` : null,
|
||||||
truck?.driverLicenseNumber ? `Driver License: ${truck.driverLicenseNumber}` : null,
|
truck?.driverLicenseNumber ? `Driver License: ${truck.driverLicenseNumber}` : null,
|
||||||
truck?.entranceTareWeightKg !== undefined ? `Entrance Tare Weight: ${Number(truck.entranceTareWeightKg)} kg` : null,
|
truck?.entranceTareWeightKg !== undefined ? `Entrance Tare Weight: ${Number(truck.entranceTareWeightKg)} kg` : null,
|
||||||
|
truck?.weighingRequired !== undefined ? `Weighing Required: ${truck.weighingRequired ? 'Yes' : 'No'}` : null,
|
||||||
truck?.exitTareWeightKg !== undefined ? `Exit Tare Weight: ${Number(truck.exitTareWeightKg)} kg` : null,
|
truck?.exitTareWeightKg !== undefined ? `Exit Tare Weight: ${Number(truck.exitTareWeightKg)} kg` : null,
|
||||||
truck?.declarationNumber ? `Declaration / Bill of Entry: ${truck.declarationNumber}` : null,
|
truck?.declarationNumber ? `Declaration / Bill of Entry: ${truck.declarationNumber}` : null,
|
||||||
truck?.incoterms ? `Incoterms: ${truck.incoterms}` : null,
|
truck?.incoterms ? `Incoterms: ${truck.incoterms}` : null,
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { Body, Controller, Get, Param, ParseUUIDPipe, Patch, Post, Query, Res }
|
|||||||
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
|
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
|
||||||
import type { Response } from 'express';
|
import type { Response } from 'express';
|
||||||
|
|
||||||
|
import { PayInvoiceDto as GatewayPayInvoiceDto } from '../billing/dto/pay-invoice.dto';
|
||||||
import { GenerateInvoiceDto, PayInvoiceBodyDto } from './dto/invoice.dto';
|
import { GenerateInvoiceDto, PayInvoiceBodyDto } from './dto/invoice.dto';
|
||||||
import { WarehouseInvoiceService } from './warehouse-invoice.service';
|
import { WarehouseInvoiceService } from './warehouse-invoice.service';
|
||||||
|
|
||||||
@@ -86,4 +87,10 @@ export class WarehouseInvoiceController {
|
|||||||
pay(@Param('id', ParseUUIDPipe) id: string, @Body() dto: PayInvoiceBodyDto) {
|
pay(@Param('id', ParseUUIDPipe) id: string, @Body() dto: PayInvoiceBodyDto) {
|
||||||
return this.invoiceService.pay(id, dto);
|
return this.invoiceService.pay(id, dto);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Post('warehouse-fee-invoices/:id/pay-online')
|
||||||
|
@ApiOperation({ summary: 'Initiate Telebirr/Waafi payment for a warehouse fee invoice' })
|
||||||
|
payOnline(@Param('id', ParseUUIDPipe) id: string, @Body() dto: GatewayPayInvoiceDto) {
|
||||||
|
return this.invoiceService.initiatePayment(id, dto);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { OnEvent } from '@nestjs/event-emitter';
|
|||||||
import { Freight } from '@edr/types';
|
import { Freight } from '@edr/types';
|
||||||
import { DataSource } from 'typeorm';
|
import { DataSource } from 'typeorm';
|
||||||
|
|
||||||
|
import { PayInvoiceDto as GatewayPayInvoiceDto } from '../billing/dto/pay-invoice.dto';
|
||||||
import { BillingService, InvoiceEventPayload, InvoiceLineInput } from '../billing/billing.service';
|
import { BillingService, InvoiceEventPayload, InvoiceLineInput } from '../billing/billing.service';
|
||||||
import { Invoice } from '../billing/entities/invoice.entity';
|
import { Invoice } from '../billing/entities/invoice.entity';
|
||||||
import { InvoiceLine } from '../billing/entities/invoice-line.entity';
|
import { InvoiceLine } from '../billing/entities/invoice-line.entity';
|
||||||
@@ -171,8 +172,12 @@ export class WarehouseInvoiceService {
|
|||||||
feeType,
|
feeType,
|
||||||
description:
|
description:
|
||||||
p.ruleType === 'STORAGE_FEE'
|
p.ruleType === 'STORAGE_FEE'
|
||||||
? `Storage fee - ${p.chargeableDays} chargeable day(s) x ${p.containerCount} container(s) after ${p.freeDays} free`
|
? `Storage fee - ${p.chargeableDays} chargeable day(s) x ${p.containerCount} container(s)${
|
||||||
: `${isContainer ? 'Container' : 'Bulk'} demurrage - ${p.chargeableDays} chargeable day(s) x ${p.containerCount} container(s) after ${p.freeDays} free`,
|
p.tiers.length ? ' using tiered tariff' : ` after ${p.freeDays} free`
|
||||||
|
}`
|
||||||
|
: `${isContainer ? 'Container' : 'Bulk'} demurrage - ${p.chargeableDays} chargeable day(s) x ${p.containerCount} container(s)${
|
||||||
|
p.tiers.length ? ' using tiered tariff' : ` after ${p.freeDays} free`
|
||||||
|
}`,
|
||||||
quantity: p.billableUnits,
|
quantity: p.billableUnits,
|
||||||
unitRate: p.ratePerDay,
|
unitRate: p.ratePerDay,
|
||||||
amount: p.amount,
|
amount: p.amount,
|
||||||
@@ -305,6 +310,22 @@ export class WarehouseInvoiceService {
|
|||||||
return detail;
|
return detail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Initiate a wallet/gateway payment for the invoice. */
|
||||||
|
async initiatePayment(id: string, dto: GatewayPayInvoiceDto = {}) {
|
||||||
|
const invoice = await this.loadWarehouseInvoice(id);
|
||||||
|
if (invoice.status === Freight.InvoiceStatus.Paid) {
|
||||||
|
throw new BadRequestException('Invoice is already fully paid.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.billing.payInvoice(invoice.source as Freight.InvoiceSource, invoice.sourceId, {
|
||||||
|
method: dto.method ?? (invoice.currency === 'USD' ? 'WAAFI' : 'TELEBIRR'),
|
||||||
|
platform: dto.platform ?? 'web',
|
||||||
|
payerAccount: dto.payerAccount,
|
||||||
|
returnUrl: dto.returnUrl,
|
||||||
|
failureUrl: dto.failureUrl,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notify on online (gateway) settlement — the domain side-effect of a warehouse
|
* Notify on online (gateway) settlement — the domain side-effect of a warehouse
|
||||||
* fee being paid through billing's payment flow. The counter {@link pay} path
|
* fee being paid through billing's payment flow. The counter {@link pay} path
|
||||||
|
|||||||
@@ -0,0 +1,627 @@
|
|||||||
|
import 'reflect-metadata';
|
||||||
|
import { config } from 'dotenv';
|
||||||
|
import { resolve } from 'path';
|
||||||
|
import { WagonStatus } from '@edr/types';
|
||||||
|
import { In } from 'typeorm';
|
||||||
|
|
||||||
|
config({ path: resolve(__dirname, '../../.env') });
|
||||||
|
|
||||||
|
import { AppDataSource } from '../data-source';
|
||||||
|
import { BookingContainer } from '../modules/bookings/entities/booking-container.entity';
|
||||||
|
import { Booking } from '../modules/bookings/entities/booking.entity';
|
||||||
|
import { CompanyProfile, ProfileStatus, ProfileType } from '../modules/companies/entities/company-profile.entity';
|
||||||
|
import { Company, CompanyKind, CompanyStatus, CompanyType } from '../modules/companies/entities/company.entity';
|
||||||
|
import { Container } from '../modules/container-management/entities/container.entity';
|
||||||
|
import { Locomotive } from '../modules/locomotives/entities/locomotive.entity';
|
||||||
|
import { ContainerType } from '../modules/rule-engine/entities/container-type.entity';
|
||||||
|
import { ServiceType } from '../modules/rule-engine/entities/service-type.entity';
|
||||||
|
import { Yard } from '../modules/rule-engine/entities/yard.entity';
|
||||||
|
import { ImportDjiboutiOperation } from '../modules/train-scheduling/entities/import-djibouti-operation.entity';
|
||||||
|
import { TrainScheduleBooking } from '../modules/train-schedules/entities/train-schedule-booking.entity';
|
||||||
|
import { WagonAllocationContainerItem } from '../modules/train-schedules/entities/wagon-allocation-container-item.entity';
|
||||||
|
import { WagonBookingAllocation } from '../modules/train-schedules/entities/wagon-booking-allocation.entity';
|
||||||
|
import { TrainSchedule } from '../modules/train-schedules/entities/train-schedule.entity';
|
||||||
|
import { TrainSetWagon } from '../modules/train-sets/entities/train-set-wagon.entity';
|
||||||
|
import { TrainSet } from '../modules/train-sets/entities/train-set.entity';
|
||||||
|
import { WagonType } from '../modules/wagon-types/entities/wagon-type.entity';
|
||||||
|
import { Wagon } from '../modules/wagons/entities/wagon.entity';
|
||||||
|
import { WarehouseInventory } from '../modules/warehouses/entities/warehouse-inventory.entity';
|
||||||
|
import { WarehouseYard } from '../modules/warehouses/entities/warehouse-yard.entity';
|
||||||
|
import { WarehouseZone } from '../modules/warehouses/entities/warehouse-zone.entity';
|
||||||
|
import { Warehouse } from '../modules/warehouses/entities/warehouse.entity';
|
||||||
|
|
||||||
|
type Direction = 'IMPORT' | 'EXPORT';
|
||||||
|
type TrainStatus = 'SCHEDULED' | 'ARRIVED';
|
||||||
|
|
||||||
|
interface ScenarioTrain {
|
||||||
|
trainNumber: string;
|
||||||
|
direction: Direction;
|
||||||
|
status: TrainStatus;
|
||||||
|
departureOffsetHours: number;
|
||||||
|
arrivalOffsetHours: number;
|
||||||
|
bookings: Array<{
|
||||||
|
reference: string;
|
||||||
|
mileVariant: 'FIRST_MILE' | 'LAST_MILE' | 'TERMINAL';
|
||||||
|
containerNumber: string;
|
||||||
|
weightTons: number;
|
||||||
|
}>;
|
||||||
|
}
|
||||||
|
|
||||||
|
const SCENARIOS: ScenarioTrain[] = [
|
||||||
|
{
|
||||||
|
trainNumber: 'GP-IMP-ARR-01',
|
||||||
|
direction: 'IMPORT',
|
||||||
|
status: 'ARRIVED',
|
||||||
|
departureOffsetHours: -18,
|
||||||
|
arrivalOffsetHours: -6,
|
||||||
|
bookings: [
|
||||||
|
{ reference: 'GP-IMP-ARR-LM-001', mileVariant: 'LAST_MILE', containerNumber: 'GPIM0000001', weightTons: 22 },
|
||||||
|
{ reference: 'GP-IMP-ARR-TM-002', mileVariant: 'TERMINAL', containerNumber: 'GPIM0000002', weightTons: 24 },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
trainNumber: 'GP-IMP-NARR-01',
|
||||||
|
direction: 'IMPORT',
|
||||||
|
status: 'SCHEDULED',
|
||||||
|
departureOffsetHours: 6,
|
||||||
|
arrivalOffsetHours: 18,
|
||||||
|
bookings: [
|
||||||
|
{ reference: 'GP-IMP-NARR-LM-001', mileVariant: 'LAST_MILE', containerNumber: 'GPIM0000003', weightTons: 21 },
|
||||||
|
{ reference: 'GP-IMP-NARR-TM-002', mileVariant: 'TERMINAL', containerNumber: 'GPIM0000004', weightTons: 23 },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
trainNumber: 'GP-EXP-ARR-01',
|
||||||
|
direction: 'EXPORT',
|
||||||
|
status: 'ARRIVED',
|
||||||
|
departureOffsetHours: -16,
|
||||||
|
arrivalOffsetHours: -4,
|
||||||
|
bookings: [
|
||||||
|
{ reference: 'GP-EXP-ARR-FM-001', mileVariant: 'FIRST_MILE', containerNumber: 'GPEX0000001', weightTons: 20 },
|
||||||
|
{ reference: 'GP-EXP-ARR-TM-002', mileVariant: 'TERMINAL', containerNumber: 'GPEX0000002', weightTons: 22 },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
trainNumber: 'GP-EXP-NARR-01',
|
||||||
|
direction: 'EXPORT',
|
||||||
|
status: 'SCHEDULED',
|
||||||
|
departureOffsetHours: 8,
|
||||||
|
arrivalOffsetHours: 20,
|
||||||
|
bookings: [
|
||||||
|
{ reference: 'GP-EXP-NARR-FM-001', mileVariant: 'FIRST_MILE', containerNumber: 'GPEX0000003', weightTons: 19 },
|
||||||
|
{ reference: 'GP-EXP-NARR-TM-002', mileVariant: 'TERMINAL', containerNumber: 'GPEX0000004', weightTons: 21 },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const addHours = (date: Date, hours: number): Date => new Date(date.getTime() + hours * 60 * 60 * 1000);
|
||||||
|
|
||||||
|
async function main() {
|
||||||
|
const dataSource = await AppDataSource.initialize();
|
||||||
|
|
||||||
|
try {
|
||||||
|
const seeded = await dataSource.transaction(async (manager) => {
|
||||||
|
if (await isAlreadySeeded(manager)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const refs = await ensureReferences(manager);
|
||||||
|
const now = new Date();
|
||||||
|
const result: Array<{ trainNumber: string; bookings: string[] }> = [];
|
||||||
|
|
||||||
|
for (const scenario of SCENARIOS) {
|
||||||
|
const schedule = await seedScenarioTrain(manager, scenario, refs, now);
|
||||||
|
result.push({
|
||||||
|
trainNumber: schedule.trainNumber ?? scenario.trainNumber,
|
||||||
|
bookings: scenario.bookings.map((booking) => booking.reference),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log('Gate-pass train scenario seed complete.');
|
||||||
|
if (seeded) {
|
||||||
|
for (const row of seeded) {
|
||||||
|
console.log(`${row.trainNumber}: ${row.bookings.join(', ')}`);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.log('Gate-pass train scenarios already seeded; nothing changed.');
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
await dataSource.destroy();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function isAlreadySeeded(manager: any): Promise<boolean> {
|
||||||
|
const scheduleRepo = manager.getRepository(TrainSchedule);
|
||||||
|
const bookingRepo = manager.getRepository(Booking);
|
||||||
|
const trainNumbers = SCENARIOS.map((scenario) => scenario.trainNumber);
|
||||||
|
const bookingRefs = SCENARIOS.flatMap((scenario) => scenario.bookings.map((booking) => booking.reference));
|
||||||
|
|
||||||
|
const [scheduleCount, bookingCount] = await Promise.all([
|
||||||
|
scheduleRepo.count({ where: { trainNumber: In(trainNumbers) } }),
|
||||||
|
bookingRepo.count({ where: { reference: In(bookingRefs) } }),
|
||||||
|
]);
|
||||||
|
|
||||||
|
return scheduleCount === trainNumbers.length && bookingCount === bookingRefs.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function ensureReferences(manager: any) {
|
||||||
|
const yardRepo = manager.getRepository(Yard);
|
||||||
|
const serviceTypeRepo = manager.getRepository(ServiceType);
|
||||||
|
const containerTypeRepo = manager.getRepository(ContainerType);
|
||||||
|
const wagonTypeRepo = manager.getRepository(WagonType);
|
||||||
|
const companyRepo = manager.getRepository(Company);
|
||||||
|
const profileRepo = manager.getRepository(CompanyProfile);
|
||||||
|
const warehouseRepo = manager.getRepository(Warehouse);
|
||||||
|
const warehouseYardRepo = manager.getRepository(WarehouseYard);
|
||||||
|
const warehouseZoneRepo = manager.getRepository(WarehouseZone);
|
||||||
|
|
||||||
|
const djiboutiYard =
|
||||||
|
(await yardRepo.findOne({ where: { code: 'NAGAD' } })) ??
|
||||||
|
(await yardRepo.findOne({ where: { code: 'DJIB_PORT' } })) ??
|
||||||
|
(await yardRepo.findOne({ where: { country: 'Djibouti' } })) ??
|
||||||
|
(await yardRepo.save(
|
||||||
|
yardRepo.create({
|
||||||
|
code: 'NAGAD',
|
||||||
|
label: 'Nagad Port',
|
||||||
|
country: 'Djibouti',
|
||||||
|
isActive: true,
|
||||||
|
displayOrder: 90,
|
||||||
|
}),
|
||||||
|
));
|
||||||
|
|
||||||
|
const ethiopiaYard =
|
||||||
|
(await yardRepo.findOne({ where: { code: 'INDODE' } })) ??
|
||||||
|
(await yardRepo.findOne({ where: { code: 'MOJO' } })) ??
|
||||||
|
(await yardRepo.findOne({ where: { country: 'Ethiopia' } })) ??
|
||||||
|
(await yardRepo.save(
|
||||||
|
yardRepo.create({
|
||||||
|
code: 'INDODE',
|
||||||
|
label: 'Indode Dry Port',
|
||||||
|
country: 'Ethiopia',
|
||||||
|
isActive: true,
|
||||||
|
displayOrder: 91,
|
||||||
|
}),
|
||||||
|
));
|
||||||
|
|
||||||
|
const serviceType =
|
||||||
|
(await serviceTypeRepo.findOne({ where: { code: 'RAIL_CONTAINER' } })) ??
|
||||||
|
(await serviceTypeRepo.save(
|
||||||
|
serviceTypeRepo.create({
|
||||||
|
code: 'RAIL_CONTAINER',
|
||||||
|
serviceName: 'Rail Container Service',
|
||||||
|
description: 'Rail container service for gate-pass scenario seed',
|
||||||
|
canBeBookedAlone: true,
|
||||||
|
includesFirstMile: false,
|
||||||
|
includesLastMile: false,
|
||||||
|
includesCustoms: false,
|
||||||
|
priorityBonusPoints: 0,
|
||||||
|
isActive: true,
|
||||||
|
displayOrder: 1,
|
||||||
|
}),
|
||||||
|
));
|
||||||
|
|
||||||
|
const containerType =
|
||||||
|
(await containerTypeRepo.findOne({ where: { code: '40FT' } })) ??
|
||||||
|
(await containerTypeRepo.findOne({ where: { isActive: true } })) ??
|
||||||
|
(await containerTypeRepo.save(
|
||||||
|
containerTypeRepo.create({
|
||||||
|
code: '40FT',
|
||||||
|
label: '40FT',
|
||||||
|
sizeFt: 40,
|
||||||
|
wagonsPerUnit: 1,
|
||||||
|
isReefer: false,
|
||||||
|
isOpenTop: false,
|
||||||
|
isActive: true,
|
||||||
|
displayOrder: 1,
|
||||||
|
}),
|
||||||
|
));
|
||||||
|
|
||||||
|
const wagonType =
|
||||||
|
(await wagonTypeRepo.findOne({ where: { code: 'GP-FLAT' } })) ??
|
||||||
|
(await wagonTypeRepo.findOne({ where: { supportsContainer: true } })) ??
|
||||||
|
(await wagonTypeRepo.findOne({ where: { isActive: true } })) ??
|
||||||
|
(await wagonTypeRepo.save(
|
||||||
|
wagonTypeRepo.create({
|
||||||
|
code: 'GP-FLAT',
|
||||||
|
name: 'Gate Pass Demo Flat Wagon',
|
||||||
|
capacityTons: 70,
|
||||||
|
lengthMeters: 14,
|
||||||
|
maxWagonsPerTrain: 53,
|
||||||
|
supportedLoadTypes: ['CONTAINER'],
|
||||||
|
isActive: true,
|
||||||
|
equatedLengthM: 14,
|
||||||
|
tareWeightTons: 20,
|
||||||
|
supportsContainer: true,
|
||||||
|
maxContainerGrossT: 70,
|
||||||
|
}),
|
||||||
|
));
|
||||||
|
|
||||||
|
const company =
|
||||||
|
(await companyRepo.findOne({ where: { tin: 'GTPASS001' } })) ??
|
||||||
|
(await companyRepo.save(
|
||||||
|
companyRepo.create({
|
||||||
|
name: 'Gate Pass Scenario Customer',
|
||||||
|
type: CompanyType.Customer,
|
||||||
|
kind: CompanyKind.Commercial,
|
||||||
|
status: CompanyStatus.Active,
|
||||||
|
tin: 'GTPASS001',
|
||||||
|
vatNumber: 'GTPASS001',
|
||||||
|
fanNumber: 'GTPASS0000001',
|
||||||
|
country: 'Ethiopia',
|
||||||
|
address: 'Indode Dry Port',
|
||||||
|
phone: '251900000555',
|
||||||
|
email: 'gate-pass-scenarios@edr.local',
|
||||||
|
contactPersonName: 'Gate Pass Tester',
|
||||||
|
contactPersonPhone: '251900000555',
|
||||||
|
}),
|
||||||
|
));
|
||||||
|
|
||||||
|
const importerProfile = await ensureProfile(profileRepo, company.id, ProfileType.importer, 'GP-IMP');
|
||||||
|
const exporterProfile = await ensureProfile(profileRepo, company.id, ProfileType.exporter, 'GP-EXP');
|
||||||
|
|
||||||
|
const warehouse =
|
||||||
|
(await warehouseRepo.findOne({ where: { code: 'INDODE_OPEN' } })) ??
|
||||||
|
(await warehouseRepo.findOne({ where: {} }));
|
||||||
|
if (!warehouse) {
|
||||||
|
throw new Error('No warehouse found. Run the Indode/warehouse seed before gate-pass scenarios.');
|
||||||
|
}
|
||||||
|
const warehouseYard = await warehouseYardRepo.findOne({ where: { warehouseId: warehouse.id } });
|
||||||
|
if (!warehouseYard) {
|
||||||
|
throw new Error(`No warehouse yard found for ${warehouse.code ?? warehouse.id}.`);
|
||||||
|
}
|
||||||
|
const warehouseZone = await warehouseZoneRepo.findOne({ where: { yardId: warehouseYard.id } });
|
||||||
|
if (!warehouseZone) {
|
||||||
|
throw new Error(`No warehouse zone found for yard ${warehouseYard.id}.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
djiboutiYard,
|
||||||
|
ethiopiaYard,
|
||||||
|
serviceType,
|
||||||
|
containerType,
|
||||||
|
wagonType,
|
||||||
|
company,
|
||||||
|
importerProfile,
|
||||||
|
exporterProfile,
|
||||||
|
warehouse,
|
||||||
|
warehouseYard,
|
||||||
|
warehouseZone,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
async function ensureProfile(repo: any, companyId: string, type: ProfileType, reference: string): Promise<CompanyProfile> {
|
||||||
|
const existing = await repo.findOne({ where: { companyId, type } });
|
||||||
|
if (existing) return existing;
|
||||||
|
return repo.save(
|
||||||
|
repo.create({
|
||||||
|
companyId,
|
||||||
|
type,
|
||||||
|
reference,
|
||||||
|
status: ProfileStatus.Active,
|
||||||
|
businessLicense: `${reference}-LICENSE`,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function seedScenarioTrain(manager: any, scenario: ScenarioTrain, refs: Awaited<ReturnType<typeof ensureReferences>>, now: Date) {
|
||||||
|
const locomotiveRepo = manager.getRepository(Locomotive);
|
||||||
|
const trainSetRepo = manager.getRepository(TrainSet);
|
||||||
|
const scheduleRepo = manager.getRepository(TrainSchedule);
|
||||||
|
const trainSetWagonRepo = manager.getRepository(TrainSetWagon);
|
||||||
|
const wagonRepo = manager.getRepository(Wagon);
|
||||||
|
|
||||||
|
const departure = addHours(now, scenario.departureOffsetHours);
|
||||||
|
const arrival = addHours(now, scenario.arrivalOffsetHours);
|
||||||
|
const isArrived = scenario.status === 'ARRIVED';
|
||||||
|
const originYard = scenario.direction === 'IMPORT' ? refs.djiboutiYard : refs.ethiopiaYard;
|
||||||
|
const destinationYard = scenario.direction === 'IMPORT' ? refs.ethiopiaYard : refs.djiboutiYard;
|
||||||
|
const totalWeightTons = scenario.bookings.reduce((sum, booking) => sum + booking.weightTons, 0);
|
||||||
|
|
||||||
|
const locomotive =
|
||||||
|
(await locomotiveRepo.findOne({ where: { code: 'GP-DEMO-LOCO' } })) ??
|
||||||
|
(await locomotiveRepo.save(
|
||||||
|
locomotiveRepo.create({
|
||||||
|
code: 'GP-DEMO-LOCO',
|
||||||
|
name: 'Gate Pass Scenario Locomotive',
|
||||||
|
locomotiveType: 'DIESEL',
|
||||||
|
maxPullWeightTons: 4200,
|
||||||
|
maxTrainLengthMeters: 760,
|
||||||
|
status: 'AVAILABLE',
|
||||||
|
currentYardId: originYard.id,
|
||||||
|
}),
|
||||||
|
));
|
||||||
|
|
||||||
|
let schedule = await scheduleRepo.findOne({ where: { trainNumber: scenario.trainNumber } });
|
||||||
|
let trainSet: TrainSet | null = schedule?.trainSetId
|
||||||
|
? await trainSetRepo.findOne({ where: { id: schedule.trainSetId } })
|
||||||
|
: null;
|
||||||
|
|
||||||
|
if (!trainSet) {
|
||||||
|
trainSet = await trainSetRepo.save(
|
||||||
|
trainSetRepo.create({
|
||||||
|
locomotiveId: locomotive.id,
|
||||||
|
totalWeightTons,
|
||||||
|
totalLengthMeters: scenario.bookings.length * 14,
|
||||||
|
wagonCount: scenario.bookings.length,
|
||||||
|
status: isArrived ? 'COMPLETED' : 'ASSIGNED',
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
await trainSetRepo.update(trainSet.id, {
|
||||||
|
locomotiveId: locomotive.id,
|
||||||
|
totalWeightTons,
|
||||||
|
totalLengthMeters: scenario.bookings.length * 14,
|
||||||
|
wagonCount: scenario.bookings.length,
|
||||||
|
status: isArrived ? 'COMPLETED' : 'ASSIGNED',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (!trainSet) {
|
||||||
|
throw new Error(`Could not create train set for ${scenario.trainNumber}`);
|
||||||
|
}
|
||||||
|
const trainSetId = trainSet.id;
|
||||||
|
|
||||||
|
if (!schedule) {
|
||||||
|
schedule = scheduleRepo.create({ trainNumber: scenario.trainNumber });
|
||||||
|
}
|
||||||
|
Object.assign(schedule, {
|
||||||
|
trainSetId,
|
||||||
|
originStationId: originYard.id,
|
||||||
|
destinationStationId: destinationYard.id,
|
||||||
|
scheduledDepartureDate: departure,
|
||||||
|
scheduledArrivalDate: arrival,
|
||||||
|
actualDepartureAt: isArrived ? departure : null,
|
||||||
|
actualArrivalAt: isArrived ? arrival : null,
|
||||||
|
status: scenario.status,
|
||||||
|
direction: scenario.direction,
|
||||||
|
maxWagons: 53,
|
||||||
|
bookingWindowStatus: 'CLOSED',
|
||||||
|
});
|
||||||
|
schedule = await scheduleRepo.save(schedule);
|
||||||
|
|
||||||
|
for (const [index, bookingSpec] of scenario.bookings.entries()) {
|
||||||
|
const sequenceNo = index + 1;
|
||||||
|
const wagon = await ensureWagon(manager, scenario, sequenceNo, refs.wagonType.id, originYard.id, schedule.id);
|
||||||
|
const trainSetWagon = await ensureTrainSetWagon(
|
||||||
|
trainSetWagonRepo,
|
||||||
|
trainSetId,
|
||||||
|
refs.wagonType.id,
|
||||||
|
wagon.id,
|
||||||
|
sequenceNo,
|
||||||
|
bookingSpec.weightTons,
|
||||||
|
isArrived,
|
||||||
|
);
|
||||||
|
await wagonRepo.update(wagon.id, { trainSetWagonId: trainSetWagon.id });
|
||||||
|
|
||||||
|
const booking = await ensureBooking(manager, scenario, bookingSpec, refs, departure, now, schedule.id);
|
||||||
|
const bookingContainer = await ensureBookingContainer(manager, booking.id, refs.containerType.id, bookingSpec);
|
||||||
|
const allocation = await ensureAllocation(manager, trainSetWagon.id, booking.id, bookingSpec.weightTons, isArrived, now);
|
||||||
|
const container = await ensureContainer(manager, booking.id, bookingContainer.id, allocation.id, wagon.id, sequenceNo, bookingSpec, refs.containerType.id, isArrived);
|
||||||
|
await ensureContainerItem(manager, allocation.id, bookingContainer.id, container.id, refs.containerType.id, sequenceNo, bookingSpec);
|
||||||
|
await ensureScheduleBooking(manager, schedule.id, booking.id);
|
||||||
|
if (scenario.direction === 'EXPORT') {
|
||||||
|
await ensureExportInventory(manager, refs, booking.id, container.id, bookingSpec.weightTons, isArrived, now);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (scenario.direction === 'IMPORT') {
|
||||||
|
await ensureImportOperation(manager, schedule.id, scenario, departure, isArrived);
|
||||||
|
}
|
||||||
|
|
||||||
|
return schedule;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function ensureWagon(manager: any, scenario: ScenarioTrain, sequenceNo: number, wagonTypeId: string, yardId: string, scheduleId: string): Promise<Wagon> {
|
||||||
|
const repo = manager.getRepository(Wagon);
|
||||||
|
const wagonNumber = `${scenario.trainNumber}-W${String(sequenceNo).padStart(2, '0')}`;
|
||||||
|
const existing = await repo.findOne({ where: { wagonNumber } });
|
||||||
|
const values = {
|
||||||
|
wagonNumber,
|
||||||
|
wagonTypeId,
|
||||||
|
trainId: null,
|
||||||
|
sequenceNumber: sequenceNo,
|
||||||
|
tareWeight: 20,
|
||||||
|
maxPayloadWeight: 70,
|
||||||
|
status: WagonStatus.Assigned,
|
||||||
|
currentYardId: yardId,
|
||||||
|
currentTrainScheduleId: scheduleId,
|
||||||
|
notes: 'Gate-pass scenario seed wagon',
|
||||||
|
};
|
||||||
|
return repo.save(repo.create({ ...(existing ?? {}), ...values }));
|
||||||
|
}
|
||||||
|
|
||||||
|
async function ensureTrainSetWagon(repo: any, trainSetId: string, wagonTypeId: string, wagonId: string, sequenceNo: number, weightTons: number, isArrived: boolean): Promise<TrainSetWagon> {
|
||||||
|
const existing = await repo.findOne({ where: { trainSetId, sequenceNo } });
|
||||||
|
return repo.save(
|
||||||
|
repo.create({
|
||||||
|
...(existing ?? {}),
|
||||||
|
trainSetId,
|
||||||
|
wagonTypeId,
|
||||||
|
physicalWagonId: wagonId,
|
||||||
|
sequenceNo,
|
||||||
|
capacityTons: 70,
|
||||||
|
lengthMeters: 14,
|
||||||
|
assignedWeightTons: weightTons,
|
||||||
|
status: isArrived ? 'DEPARTED' : 'LOADED',
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function ensureBooking(manager: any, scenario: ScenarioTrain, bookingSpec: ScenarioTrain['bookings'][number], refs: Awaited<ReturnType<typeof ensureReferences>>, departure: Date, now: Date, scheduleId: string): Promise<Booking> {
|
||||||
|
const repo = manager.getRepository(Booking);
|
||||||
|
const originYard = scenario.direction === 'IMPORT' ? refs.djiboutiYard : refs.ethiopiaYard;
|
||||||
|
const destinationYard = scenario.direction === 'IMPORT' ? refs.ethiopiaYard : refs.djiboutiYard;
|
||||||
|
const existing = await repo.findOne({ where: { reference: bookingSpec.reference } });
|
||||||
|
const profile = scenario.direction === 'IMPORT' ? refs.importerProfile : refs.exporterProfile;
|
||||||
|
const hasFirstMile = bookingSpec.mileVariant === 'FIRST_MILE';
|
||||||
|
const hasLastMile = bookingSpec.mileVariant === 'LAST_MILE';
|
||||||
|
|
||||||
|
return repo.save(
|
||||||
|
repo.create({
|
||||||
|
...(existing ?? {}),
|
||||||
|
reference: bookingSpec.reference,
|
||||||
|
companyId: refs.company.id,
|
||||||
|
companyProfileId: profile.id,
|
||||||
|
originYardId: originYard.id,
|
||||||
|
destinationYardId: destinationYard.id,
|
||||||
|
serviceTypeId: refs.serviceType.id,
|
||||||
|
status: scenario.status === 'ARRIVED' ? 'IN_TRANSIT' : 'PAID',
|
||||||
|
paymentStatus: 'PAID',
|
||||||
|
scheduledDate: departure,
|
||||||
|
estimatedShipmentDate: departure,
|
||||||
|
contractType: 'SPOT',
|
||||||
|
equipmentReturn: 'TERMINAL',
|
||||||
|
paymentCurrency: 'ETB',
|
||||||
|
totalAmount: 0,
|
||||||
|
isGovernment: false,
|
||||||
|
tradeDirection: scenario.direction,
|
||||||
|
freightType: 'CONTAINER',
|
||||||
|
cargoTypeId: null,
|
||||||
|
cargoFreeText: `${scenario.direction} gate-pass scenario ${bookingSpec.mileVariant.toLowerCase().replace('_', ' ')}`,
|
||||||
|
cargoTotalWeightVgm: bookingSpec.weightTons * 1000,
|
||||||
|
firstMilePickupAddress: hasFirstMile ? 'Customer factory pickup - Addis Ababa' : null,
|
||||||
|
firstMilePickupLat: hasFirstMile ? 9.03 : null,
|
||||||
|
firstMilePickupLng: hasFirstMile ? 38.74 : null,
|
||||||
|
lastMileDeliveryAddress: hasLastMile ? 'Customer warehouse delivery - Addis Ababa' : null,
|
||||||
|
lastMileDeliveryLat: hasLastMile ? 8.98 : null,
|
||||||
|
lastMileDeliveryLng: hasLastMile ? 38.8 : null,
|
||||||
|
trainScheduleId: scheduleId,
|
||||||
|
schedulingStatus: scenario.status === 'ARRIVED' ? 'DISPATCHED' : 'SCHEDULED',
|
||||||
|
scheduledAt: now,
|
||||||
|
wagonsRequired: 1,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function ensureBookingContainer(manager: any, bookingId: string, containerTypeId: string, bookingSpec: ScenarioTrain['bookings'][number]): Promise<BookingContainer> {
|
||||||
|
const repo = manager.getRepository(BookingContainer);
|
||||||
|
const existing = await repo.findOne({ where: { bookingId } });
|
||||||
|
return repo.save(
|
||||||
|
repo.create({
|
||||||
|
...(existing ?? {}),
|
||||||
|
bookingId,
|
||||||
|
containerTypeId,
|
||||||
|
containerNumber: bookingSpec.containerNumber,
|
||||||
|
containerSize: '40',
|
||||||
|
quantity: 1,
|
||||||
|
hazardousQuantity: 0,
|
||||||
|
reeferQuantity: 0,
|
||||||
|
vgmPerUnitTons: bookingSpec.weightTons,
|
||||||
|
totalVgmTons: bookingSpec.weightTons,
|
||||||
|
wagonsRequired: 1,
|
||||||
|
weightLimitRuleId: null,
|
||||||
|
isOverweight: false,
|
||||||
|
overweightExcessTons: null,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function ensureAllocation(manager: any, trainSetWagonId: string, bookingId: string, weightTons: number, isArrived: boolean, now: Date): Promise<WagonBookingAllocation> {
|
||||||
|
const repo = manager.getRepository(WagonBookingAllocation);
|
||||||
|
const existing = await repo.findOne({ where: { trainSetWagonId, bookingId } });
|
||||||
|
return repo.save(
|
||||||
|
repo.create({
|
||||||
|
...(existing ?? {}),
|
||||||
|
trainSetWagonId,
|
||||||
|
bookingId,
|
||||||
|
allocatedWeightTons: weightTons,
|
||||||
|
loadType: 'CONTAINER',
|
||||||
|
status: isArrived ? 'DEPARTED' : 'LOADED',
|
||||||
|
confirmedAt: now,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function ensureContainer(manager: any, bookingId: string, bookingContainerId: string, allocationId: string, wagonId: string, position: number, bookingSpec: ScenarioTrain['bookings'][number], containerTypeId: string, isArrived: boolean): Promise<Container> {
|
||||||
|
const repo = manager.getRepository(Container);
|
||||||
|
const existing = await repo.findOne({ where: { containerNumber: bookingSpec.containerNumber } });
|
||||||
|
return repo.save(
|
||||||
|
repo.create({
|
||||||
|
...(existing ?? {}),
|
||||||
|
containerNumber: bookingSpec.containerNumber,
|
||||||
|
containerTypeId,
|
||||||
|
wagonId,
|
||||||
|
position,
|
||||||
|
tareWeight: 3800,
|
||||||
|
maxGrossWeight: 30480,
|
||||||
|
sealNumber: `SEAL-${bookingSpec.containerNumber}`,
|
||||||
|
status: isArrived ? 'IN_TRANSIT' : 'LOADED',
|
||||||
|
bookingId,
|
||||||
|
wagonBookingAllocationId: allocationId,
|
||||||
|
bookingContainerId,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function ensureContainerItem(manager: any, allocationId: string, bookingContainerId: string, containerId: string, containerTypeId: string, position: number, bookingSpec: ScenarioTrain['bookings'][number]): Promise<void> {
|
||||||
|
const repo = manager.getRepository(WagonAllocationContainerItem);
|
||||||
|
await repo.delete({ wagonBookingAllocationId: allocationId });
|
||||||
|
await repo.save(
|
||||||
|
repo.create({
|
||||||
|
wagonBookingAllocationId: allocationId,
|
||||||
|
bookingContainerId,
|
||||||
|
containerId,
|
||||||
|
containerNumber: bookingSpec.containerNumber,
|
||||||
|
containerTypeId,
|
||||||
|
positionOnWagon: position,
|
||||||
|
sealNumber: `SEAL-${bookingSpec.containerNumber}`,
|
||||||
|
chassisNumber: `CHS-${bookingSpec.containerNumber}`,
|
||||||
|
grossWeightTons: bookingSpec.weightTons,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function ensureScheduleBooking(manager: any, scheduleId: string, bookingId: string): Promise<void> {
|
||||||
|
const repo = manager.getRepository(TrainScheduleBooking);
|
||||||
|
const existing = await repo.findOne({ where: { bookingId } });
|
||||||
|
await repo.save(repo.create({ ...(existing ?? {}), trainScheduleId: scheduleId, bookingId }));
|
||||||
|
}
|
||||||
|
|
||||||
|
async function ensureExportInventory(manager: any, refs: Awaited<ReturnType<typeof ensureReferences>>, bookingId: string, containerId: string, weightTons: number, isArrived: boolean, now: Date): Promise<void> {
|
||||||
|
const repo = manager.getRepository(WarehouseInventory);
|
||||||
|
const existing = await repo.findOne({ where: { bookingId } });
|
||||||
|
await repo.save(
|
||||||
|
repo.create({
|
||||||
|
...(existing ?? {}),
|
||||||
|
warehouseId: refs.warehouse.id,
|
||||||
|
yardId: refs.warehouseYard.id,
|
||||||
|
zoneId: refs.warehouseZone.id,
|
||||||
|
bookingId,
|
||||||
|
containerId,
|
||||||
|
quantity: 1,
|
||||||
|
weight: weightTons * 1000,
|
||||||
|
status: 'LOADED',
|
||||||
|
inspectionStatus: 'PASSED',
|
||||||
|
arrivedAt: addHours(now, -24),
|
||||||
|
inspectedAt: addHours(now, -22),
|
||||||
|
readyForLoadingAt: addHours(now, -20),
|
||||||
|
loadedAt: isArrived ? addHours(now, -16) : null,
|
||||||
|
notes: '[GP-SCENARIO] Export train gate-pass scenario inventory',
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function ensureImportOperation(manager: any, scheduleId: string, scenario: ScenarioTrain, departure: Date, isArrived: boolean): Promise<void> {
|
||||||
|
const repo = manager.getRepository(ImportDjiboutiOperation);
|
||||||
|
const existing = await repo.findOne({ where: { trainScheduleId: scheduleId } });
|
||||||
|
await repo.save(
|
||||||
|
repo.create({
|
||||||
|
...(existing ?? {}),
|
||||||
|
trainScheduleId: scheduleId,
|
||||||
|
documents: existing?.documents ?? {},
|
||||||
|
gatepassGrantedAt: null,
|
||||||
|
readyForLoadingAt: null,
|
||||||
|
loadedOnTrainAt: null,
|
||||||
|
departedFromDjiboutiAt: isArrived ? departure : null,
|
||||||
|
loadListGeneratedAt: null,
|
||||||
|
performedBy: 'Gate Pass Scenario Seeder',
|
||||||
|
notes: `[GP-SCENARIO] ${scenario.trainNumber}; fill gate-pass dates during testing`,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
main().catch((error) => {
|
||||||
|
console.error('Gate-pass train scenario seed failed:', error);
|
||||||
|
process.exit(1);
|
||||||
|
});
|
||||||
1131
apps/edr-freight-api/src/seed/paid-indode-demo-bookings.seeder.ts
Normal file
1131
apps/edr-freight-api/src/seed/paid-indode-demo-bookings.seeder.ts
Normal file
File diff suppressed because it is too large
Load Diff
1
apps/edr-freight-api/src/types/multer-globals.d.ts
vendored
Normal file
1
apps/edr-freight-api/src/types/multer-globals.d.ts
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
/// <reference types="multer" />
|
||||||
@@ -72,6 +72,13 @@ function FeeCard({ fee }: { fee: FeePreview }) {
|
|||||||
<Row label="Chargeable days" value={`${fee.chargeableDays} (after ${fee.freeDays} free)`} />
|
<Row label="Chargeable days" value={`${fee.chargeableDays} (after ${fee.freeDays} free)`} />
|
||||||
<Row label="Containers" value={String(fee.containerCount ?? 1)} />
|
<Row label="Containers" value={String(fee.containerCount ?? 1)} />
|
||||||
<Row label="Billable units" value={`${fee.billableUnits ?? fee.chargeableDays} container-day(s)`} />
|
<Row label="Billable units" value={`${fee.billableUnits ?? fee.chargeableDays} container-day(s)`} />
|
||||||
|
{(fee.tiers ?? []).map((tier) => (
|
||||||
|
<Row
|
||||||
|
key={`${tier.appliedFromDay}-${tier.appliedToDay}-${tier.ratePerDay}`}
|
||||||
|
label={`Days ${tier.appliedFromDay}-${tier.appliedToDay}`}
|
||||||
|
value={`${tier.days} x ${money(tier.ratePerDay, fee.currency)} = ${money(tier.amount, fee.currency)}`}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
</Stack>
|
</Stack>
|
||||||
)}
|
)}
|
||||||
</Card>
|
</Card>
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
|||||||
import { api } from '@/services/api';
|
import { api } from '@/services/api';
|
||||||
import { QUERY_KEYS } from '@/constants/QUERY_KEYS';
|
import { QUERY_KEYS } from '@/constants/QUERY_KEYS';
|
||||||
import { useToast } from '@/hooks/use-toast';
|
import { useToast } from '@/hooks/use-toast';
|
||||||
import { useInventoryInquiry } from '@/hooks/useWarehouses';
|
import { useAllWarehouseYards, useAllWarehouseZones, useInventoryInquiry } from '@/hooks/useWarehouses';
|
||||||
import { firstMileService } from '@/services/first-mile.service';
|
import { firstMileService } from '@/services/first-mile.service';
|
||||||
import { warehouseService } from '@/services/warehouse.service';
|
import { warehouseService } from '@/services/warehouse.service';
|
||||||
import type {
|
import type {
|
||||||
@@ -54,7 +54,10 @@ import type {
|
|||||||
ReadyToLoadRow,
|
ReadyToLoadRow,
|
||||||
ReceiveInventoryPayload,
|
ReceiveInventoryPayload,
|
||||||
TruckEntrancePayload,
|
TruckEntrancePayload,
|
||||||
|
Warehouse,
|
||||||
WarehouseInventoryItem,
|
WarehouseInventoryItem,
|
||||||
|
WarehouseYard,
|
||||||
|
WarehouseZone,
|
||||||
} from '@/types/warehouse';
|
} from '@/types/warehouse';
|
||||||
import { BookingSelect } from './BookingSelect';
|
import { BookingSelect } from './BookingSelect';
|
||||||
import { DeliverInventoryModal } from './DeliverInventoryModal';
|
import { DeliverInventoryModal } from './DeliverInventoryModal';
|
||||||
@@ -70,12 +73,17 @@ import { extractErrorMessage, formatDate, formatNumber, inventoryStatusOptions }
|
|||||||
import { openPdfBlob } from './pdf';
|
import { openPdfBlob } from './pdf';
|
||||||
import '@/components/overview/overview.css';
|
import '@/components/overview/overview.css';
|
||||||
|
|
||||||
|
type ImportUnloadAssignment = { bookingId: string; warehouseId: string; yardId: string; zoneId: string };
|
||||||
|
type ImportUnloadAssignmentDraft = Partial<Omit<ImportUnloadAssignment, 'bookingId'>>;
|
||||||
|
|
||||||
interface ReceiveInventoryModalProps {
|
interface ReceiveInventoryModalProps {
|
||||||
opened: boolean;
|
opened: boolean;
|
||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
/** When supplied the modal locks to a single booking (legacy single-receive). */
|
/** When supplied the modal locks to a single booking (legacy single-receive). */
|
||||||
bookingId?: string;
|
bookingId?: string;
|
||||||
bookingLabel?: string;
|
bookingLabel?: string;
|
||||||
|
mode?: 'single' | 'bulk';
|
||||||
|
direction?: WarehouseFlowDirection;
|
||||||
onReceived?: () => void;
|
onReceived?: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -142,6 +150,7 @@ interface TruckEntranceFormState {
|
|||||||
packagingType: string;
|
packagingType: string;
|
||||||
unitCount: number | '';
|
unitCount: number | '';
|
||||||
grossWeightKg: number | '';
|
grossWeightKg: number | '';
|
||||||
|
weighingRequired: boolean | null;
|
||||||
netWeightKg: number | '';
|
netWeightKg: number | '';
|
||||||
volumeDimensions: string;
|
volumeDimensions: string;
|
||||||
conditionAtReceipt: string;
|
conditionAtReceipt: string;
|
||||||
@@ -163,11 +172,17 @@ interface LockedTruckEntranceFields {
|
|||||||
tin?: boolean;
|
tin?: boolean;
|
||||||
edrDigitalBookingId?: boolean;
|
edrDigitalBookingId?: boolean;
|
||||||
customerPhone?: boolean;
|
customerPhone?: boolean;
|
||||||
|
truckPlateNumber?: boolean;
|
||||||
|
trailerPlateNumber?: boolean;
|
||||||
assignedEquipmentNumber?: boolean;
|
assignedEquipmentNumber?: boolean;
|
||||||
itemDescription?: boolean;
|
itemDescription?: boolean;
|
||||||
packagingType?: boolean;
|
packagingType?: boolean;
|
||||||
unitCount?: boolean;
|
unitCount?: boolean;
|
||||||
grossWeightKg?: boolean;
|
grossWeightKg?: boolean;
|
||||||
|
driverName?: boolean;
|
||||||
|
driverPhone?: boolean;
|
||||||
|
driverLicenseNumber?: boolean;
|
||||||
|
truckType?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
type PackagingFreightType = 'CONTAINER' | 'BULK' | 'MIXED';
|
type PackagingFreightType = 'CONTAINER' | 'BULK' | 'MIXED';
|
||||||
@@ -190,6 +205,7 @@ const emptyTruckEntrance = (): TruckEntranceFormState => ({
|
|||||||
packagingType: '',
|
packagingType: '',
|
||||||
unitCount: '',
|
unitCount: '',
|
||||||
grossWeightKg: '',
|
grossWeightKg: '',
|
||||||
|
weighingRequired: null,
|
||||||
netWeightKg: '',
|
netWeightKg: '',
|
||||||
volumeDimensions: '',
|
volumeDimensions: '',
|
||||||
conditionAtReceipt: '',
|
conditionAtReceipt: '',
|
||||||
@@ -206,13 +222,24 @@ const emptyTruckEntrance = (): TruckEntranceFormState => ({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const toTruckEntrancePayload = (form: TruckEntranceFormState): TruckEntrancePayload => ({
|
const toTruckEntrancePayload = (form: TruckEntranceFormState): TruckEntrancePayload => ({
|
||||||
|
ownerName: form.ownerName.trim() || undefined,
|
||||||
|
consigneeDetails: form.consigneeDetails.trim() || undefined,
|
||||||
|
edrDigitalBookingId: form.edrDigitalBookingId.trim() || undefined,
|
||||||
|
tin: form.tin.trim() || undefined,
|
||||||
|
customerPhone: form.customerPhone.trim() || undefined,
|
||||||
truckPlateNumber: form.truckPlateNumber.trim(),
|
truckPlateNumber: form.truckPlateNumber.trim(),
|
||||||
trailerPlateNumber: form.trailerPlateNumber.trim() || undefined,
|
trailerPlateNumber: form.trailerPlateNumber.trim() || undefined,
|
||||||
|
assignedEquipmentNumber: form.assignedEquipmentNumber.trim() || undefined,
|
||||||
customsSealNumber: form.customsSealNumber.trim() || undefined,
|
customsSealNumber: form.customsSealNumber.trim() || undefined,
|
||||||
declarationNumber: form.declarationNumber.trim() || undefined,
|
declarationNumber: form.declarationNumber.trim() || undefined,
|
||||||
incoterms: form.incoterms.trim() || undefined,
|
incoterms: form.incoterms.trim() || undefined,
|
||||||
hsCodes: form.hsCodes.trim() || undefined,
|
hsCodes: form.hsCodes.trim() || undefined,
|
||||||
itemCode: form.itemCode.trim() || undefined,
|
itemCode: form.itemCode.trim() || undefined,
|
||||||
|
itemDescription: form.itemDescription.trim() || undefined,
|
||||||
|
packagingType: form.packagingType.trim() || undefined,
|
||||||
|
unitCount: form.unitCount === '' ? undefined : Number(form.unitCount),
|
||||||
|
weighingRequired: form.weighingRequired ?? undefined,
|
||||||
|
grossWeightKg: form.weighingRequired && form.grossWeightKg !== '' ? Number(form.grossWeightKg) : undefined,
|
||||||
netWeightKg: form.netWeightKg === '' ? undefined : Number(form.netWeightKg),
|
netWeightKg: form.netWeightKg === '' ? undefined : Number(form.netWeightKg),
|
||||||
volumeDimensions: form.volumeDimensions.trim() || undefined,
|
volumeDimensions: form.volumeDimensions.trim() || undefined,
|
||||||
conditionAtReceipt: form.conditionAtReceipt.trim() || undefined,
|
conditionAtReceipt: form.conditionAtReceipt.trim() || undefined,
|
||||||
@@ -222,8 +249,11 @@ const toTruckEntrancePayload = (form: TruckEntranceFormState): TruckEntrancePayl
|
|||||||
driverPhone: form.driverPhone.trim(),
|
driverPhone: form.driverPhone.trim(),
|
||||||
driverLicenseNumber: form.driverLicenseNumber.trim() || undefined,
|
driverLicenseNumber: form.driverLicenseNumber.trim() || undefined,
|
||||||
truckType: form.truckType.trim() || undefined,
|
truckType: form.truckType.trim() || undefined,
|
||||||
entranceTareWeightKg: Number(form.entranceTareWeightKg),
|
entranceTareWeightKg:
|
||||||
exitTareWeightKg: form.exitTareWeightKg === '' ? undefined : Number(form.exitTareWeightKg),
|
form.entranceTareWeightKg === ''
|
||||||
|
? undefined
|
||||||
|
: Number(form.entranceTareWeightKg),
|
||||||
|
exitTareWeightKg: form.weighingRequired && form.exitTareWeightKg !== '' ? Number(form.exitTareWeightKg) : undefined,
|
||||||
driverSignatoryName: form.driverSignatoryName.trim() || undefined,
|
driverSignatoryName: form.driverSignatoryName.trim() || undefined,
|
||||||
warehouseManagerName: form.warehouseManagerName.trim() || undefined,
|
warehouseManagerName: form.warehouseManagerName.trim() || undefined,
|
||||||
});
|
});
|
||||||
@@ -242,22 +272,31 @@ const truckEntranceFromBookings = (bookings: EligibleBooking[]): {
|
|||||||
const tin = commonNonEmptyValue(bookings.map((booking) => booking.customerTin));
|
const tin = commonNonEmptyValue(bookings.map((booking) => booking.customerTin));
|
||||||
const customerPhone = commonNonEmptyValue(bookings.map((booking) => booking.customerPhone));
|
const customerPhone = commonNonEmptyValue(bookings.map((booking) => booking.customerPhone));
|
||||||
const consigneeDetails = commonNonEmptyValue(bookings.map((booking) => booking.customer));
|
const consigneeDetails = commonNonEmptyValue(bookings.map((booking) => booking.customer));
|
||||||
const assignedEquipmentNumber = commonNonEmptyValue(bookings.map((booking) => booking.containerNumber));
|
const assignedEquipmentNumber = commonNonEmptyValue(
|
||||||
|
bookings.map((booking) => booking.customerTruckContainerNumber || booking.containerNumber),
|
||||||
|
);
|
||||||
const itemDescription = commonNonEmptyValue(bookings.map((booking) => booking.cargoDescription ?? booking.cargo));
|
const itemDescription = commonNonEmptyValue(bookings.map((booking) => booking.cargoDescription ?? booking.cargo));
|
||||||
const packagingType = commonNonEmptyValue(bookings.map((booking) => booking.containerPackagingType));
|
const packagingType = commonNonEmptyValue(bookings.map((booking) => booking.containerPackagingType));
|
||||||
|
const truckPlateNumber = commonNonEmptyValue(
|
||||||
|
bookings.map((booking) => booking.firstMileTruckPlateNumber || booking.customerTruckPlateNumber),
|
||||||
|
);
|
||||||
|
const trailerPlateNumber = commonNonEmptyValue(bookings.map((booking) => booking.firstMileTrailerPlateNumber));
|
||||||
|
const driverName = commonNonEmptyValue(
|
||||||
|
bookings.map((booking) => booking.firstMileDriverName || booking.customerTruckDriverName),
|
||||||
|
);
|
||||||
|
const driverPhone = commonNonEmptyValue(bookings.map((booking) => booking.firstMileDriverPhone));
|
||||||
|
const driverLicenseNumber = commonNonEmptyValue(bookings.map((booking) => booking.firstMileDriverLicenseNumber));
|
||||||
|
const truckType = commonNonEmptyValue(
|
||||||
|
bookings.map((booking) => booking.firstMileTruckType || booking.customerTruckType),
|
||||||
|
);
|
||||||
const edrDigitalBookingId =
|
const edrDigitalBookingId =
|
||||||
bookings.length === 1
|
bookings.length === 1
|
||||||
? bookings[0]?.reference ?? bookings[0]?.id ?? ''
|
? bookings[0]?.reference ?? bookings[0]?.id ?? ''
|
||||||
: commonNonEmptyValue(bookings.map((booking) => booking.reference));
|
: commonNonEmptyValue(bookings.map((booking) => booking.reference));
|
||||||
const firstMileBooking = bookings.length === 1 ? bookings[0] : null;
|
|
||||||
const unitCount =
|
const unitCount =
|
||||||
bookings.length === 1 && bookings[0]?.containerQuantity != null
|
bookings.length === 1 && bookings[0]?.containerQuantity != null
|
||||||
? Number(bookings[0].containerQuantity)
|
? Number(bookings[0].containerQuantity)
|
||||||
: '';
|
: '';
|
||||||
const grossWeightKg =
|
|
||||||
bookings.length === 1 && bookings[0]?.weight != null
|
|
||||||
? Number(bookings[0].weight)
|
|
||||||
: '';
|
|
||||||
const freightTypes = [...new Set(bookings.map((booking) => booking.freightType).filter(Boolean))];
|
const freightTypes = [...new Set(bookings.map((booking) => booking.freightType).filter(Boolean))];
|
||||||
const packagingFreightType =
|
const packagingFreightType =
|
||||||
freightTypes.length === 1 && freightTypes[0] === 'CONTAINER'
|
freightTypes.length === 1 && freightTypes[0] === 'CONTAINER'
|
||||||
@@ -278,13 +317,13 @@ const truckEntranceFromBookings = (bookings: EligibleBooking[]): {
|
|||||||
itemDescription,
|
itemDescription,
|
||||||
packagingType,
|
packagingType,
|
||||||
unitCount,
|
unitCount,
|
||||||
grossWeightKg,
|
grossWeightKg: '',
|
||||||
truckPlateNumber: firstMileBooking?.firstMileTruckPlateNumber ?? '',
|
truckPlateNumber,
|
||||||
trailerPlateNumber: firstMileBooking?.firstMileTrailerPlateNumber ?? '',
|
trailerPlateNumber,
|
||||||
driverName: firstMileBooking?.firstMileDriverName ?? '',
|
driverName,
|
||||||
driverPhone: firstMileBooking?.firstMileDriverPhone ?? '',
|
driverPhone,
|
||||||
driverLicenseNumber: firstMileBooking?.firstMileDriverLicenseNumber ?? '',
|
driverLicenseNumber,
|
||||||
truckType: firstMileBooking?.firstMileTruckType ?? '',
|
truckType,
|
||||||
},
|
},
|
||||||
lockedFields: {
|
lockedFields: {
|
||||||
ownerName: Boolean(ownerName),
|
ownerName: Boolean(ownerName),
|
||||||
@@ -296,7 +335,13 @@ const truckEntranceFromBookings = (bookings: EligibleBooking[]): {
|
|||||||
itemDescription: Boolean(itemDescription),
|
itemDescription: Boolean(itemDescription),
|
||||||
packagingType: Boolean(packagingType),
|
packagingType: Boolean(packagingType),
|
||||||
unitCount: unitCount !== '',
|
unitCount: unitCount !== '',
|
||||||
grossWeightKg: grossWeightKg !== '',
|
grossWeightKg: false,
|
||||||
|
truckPlateNumber: Boolean(truckPlateNumber),
|
||||||
|
trailerPlateNumber: Boolean(trailerPlateNumber),
|
||||||
|
driverName: Boolean(driverName),
|
||||||
|
driverPhone: Boolean(driverPhone),
|
||||||
|
driverLicenseNumber: Boolean(driverLicenseNumber),
|
||||||
|
truckType: Boolean(truckType),
|
||||||
},
|
},
|
||||||
packagingFreightType,
|
packagingFreightType,
|
||||||
};
|
};
|
||||||
@@ -338,11 +383,13 @@ function TruckEntranceFields({
|
|||||||
onChange,
|
onChange,
|
||||||
lockedFields,
|
lockedFields,
|
||||||
packagingFreightType = 'MIXED',
|
packagingFreightType = 'MIXED',
|
||||||
|
allowTruckWeighing = true,
|
||||||
}: {
|
}: {
|
||||||
value: TruckEntranceFormState;
|
value: TruckEntranceFormState;
|
||||||
onChange: (next: TruckEntranceFormState) => void;
|
onChange: (next: TruckEntranceFormState) => void;
|
||||||
lockedFields?: LockedTruckEntranceFields;
|
lockedFields?: LockedTruckEntranceFields;
|
||||||
packagingFreightType?: PackagingFreightType;
|
packagingFreightType?: PackagingFreightType;
|
||||||
|
allowTruckWeighing?: boolean;
|
||||||
}) {
|
}) {
|
||||||
const packagingOptions = packagingOptionsFor(packagingFreightType);
|
const packagingOptions = packagingOptionsFor(packagingFreightType);
|
||||||
const quantityLabel =
|
const quantityLabel =
|
||||||
@@ -396,11 +443,13 @@ function TruckEntranceFields({
|
|||||||
label="Truck plate number"
|
label="Truck plate number"
|
||||||
required
|
required
|
||||||
value={value.truckPlateNumber}
|
value={value.truckPlateNumber}
|
||||||
|
readOnly={lockedFields?.truckPlateNumber}
|
||||||
onChange={(e) => onChange({ ...value, truckPlateNumber: e.currentTarget.value })}
|
onChange={(e) => onChange({ ...value, truckPlateNumber: e.currentTarget.value })}
|
||||||
/>
|
/>
|
||||||
<TextInput
|
<TextInput
|
||||||
label="Trailer plate number"
|
label="Trailer plate number"
|
||||||
value={value.trailerPlateNumber}
|
value={value.trailerPlateNumber}
|
||||||
|
readOnly={lockedFields?.trailerPlateNumber}
|
||||||
onChange={(e) => onChange({ ...value, trailerPlateNumber: e.currentTarget.value })}
|
onChange={(e) => onChange({ ...value, trailerPlateNumber: e.currentTarget.value })}
|
||||||
/>
|
/>
|
||||||
</Group>
|
</Group>
|
||||||
@@ -422,12 +471,14 @@ function TruckEntranceFields({
|
|||||||
label="Driver name"
|
label="Driver name"
|
||||||
required
|
required
|
||||||
value={value.driverName}
|
value={value.driverName}
|
||||||
|
readOnly={lockedFields?.driverName}
|
||||||
onChange={(e) => onChange({ ...value, driverName: e.currentTarget.value })}
|
onChange={(e) => onChange({ ...value, driverName: e.currentTarget.value })}
|
||||||
/>
|
/>
|
||||||
<TextInput
|
<TextInput
|
||||||
label="Driver phone"
|
label="Driver phone"
|
||||||
required
|
required
|
||||||
value={value.driverPhone}
|
value={value.driverPhone}
|
||||||
|
readOnly={lockedFields?.driverPhone}
|
||||||
onChange={(e) => onChange({ ...value, driverPhone: e.currentTarget.value })}
|
onChange={(e) => onChange({ ...value, driverPhone: e.currentTarget.value })}
|
||||||
/>
|
/>
|
||||||
</Group>
|
</Group>
|
||||||
@@ -435,29 +486,61 @@ function TruckEntranceFields({
|
|||||||
<TextInput
|
<TextInput
|
||||||
label="Driver license number"
|
label="Driver license number"
|
||||||
value={value.driverLicenseNumber}
|
value={value.driverLicenseNumber}
|
||||||
|
readOnly={lockedFields?.driverLicenseNumber}
|
||||||
onChange={(e) => onChange({ ...value, driverLicenseNumber: e.currentTarget.value })}
|
onChange={(e) => onChange({ ...value, driverLicenseNumber: e.currentTarget.value })}
|
||||||
/>
|
/>
|
||||||
<TextInput
|
<TextInput
|
||||||
label="Truck type"
|
label="Truck type"
|
||||||
value={value.truckType}
|
value={value.truckType}
|
||||||
|
readOnly={lockedFields?.truckType}
|
||||||
onChange={(e) => onChange({ ...value, truckType: e.currentTarget.value })}
|
onChange={(e) => onChange({ ...value, truckType: e.currentTarget.value })}
|
||||||
/>
|
/>
|
||||||
</Group>
|
</Group>
|
||||||
<Group grow>
|
{allowTruckWeighing ? (
|
||||||
<NumberInput
|
<>
|
||||||
label="Entrance tare weight (kg)"
|
<Select
|
||||||
required
|
label="Weighing"
|
||||||
min={0}
|
required
|
||||||
value={value.entranceTareWeightKg}
|
data={[
|
||||||
onChange={(v) => onChange({ ...value, entranceTareWeightKg: v === '' ? '' : Number(v) })}
|
{ value: 'YES', label: 'Yes' },
|
||||||
/>
|
{ value: 'NO', label: 'No' },
|
||||||
<NumberInput
|
]}
|
||||||
label="Exit tare weight (kg)"
|
value={value.weighingRequired == null ? null : value.weighingRequired ? 'YES' : 'NO'}
|
||||||
min={0}
|
onChange={(next) =>
|
||||||
value={value.exitTareWeightKg}
|
onChange({
|
||||||
onChange={(v) => onChange({ ...value, exitTareWeightKg: v === '' ? '' : Number(v) })}
|
...value,
|
||||||
/>
|
weighingRequired: next === 'YES' ? true : next === 'NO' ? false : null,
|
||||||
</Group>
|
grossWeightKg: next === 'YES' ? value.grossWeightKg : '',
|
||||||
|
exitTareWeightKg: next === 'YES' ? value.exitTareWeightKg : '',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
{value.weighingRequired && (
|
||||||
|
<Group grow>
|
||||||
|
<NumberInput
|
||||||
|
label="Gross weight (kg)"
|
||||||
|
required
|
||||||
|
min={0}
|
||||||
|
value={value.grossWeightKg}
|
||||||
|
onChange={(v) => onChange({ ...value, grossWeightKg: v === '' ? '' : Number(v) })}
|
||||||
|
/>
|
||||||
|
<NumberInput
|
||||||
|
label="Exit tare weight (kg)"
|
||||||
|
required
|
||||||
|
min={0}
|
||||||
|
value={value.exitTareWeightKg}
|
||||||
|
onChange={(v) => onChange({ ...value, exitTareWeightKg: v === '' ? '' : Number(v) })}
|
||||||
|
/>
|
||||||
|
</Group>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<Alert icon={<Info size={16} />} color="green" variant="light">
|
||||||
|
<Text size="sm">
|
||||||
|
Truck weighing is not required for a received first-mile arrival. The GRN uses the booking weight.
|
||||||
|
</Text>
|
||||||
|
</Alert>
|
||||||
|
)}
|
||||||
|
|
||||||
<Text size="sm" fw={600} mt="xs">Customs and compliance</Text>
|
<Text size="sm" fw={600} mt="xs">Customs and compliance</Text>
|
||||||
<Group grow>
|
<Group grow>
|
||||||
@@ -510,21 +593,12 @@ function TruckEntranceFields({
|
|||||||
onChange={(v) => onChange({ ...value, unitCount: v === '' ? '' : Number(v) })}
|
onChange={(v) => onChange({ ...value, unitCount: v === '' ? '' : Number(v) })}
|
||||||
/>
|
/>
|
||||||
</Group>
|
</Group>
|
||||||
<Group grow>
|
<NumberInput
|
||||||
<NumberInput
|
label="Net weight (kg)"
|
||||||
label="Gross weight (kg)"
|
min={0}
|
||||||
min={0}
|
value={value.netWeightKg}
|
||||||
value={value.grossWeightKg}
|
onChange={(v) => onChange({ ...value, netWeightKg: v === '' ? '' : Number(v) })}
|
||||||
readOnly={lockedFields?.grossWeightKg}
|
/>
|
||||||
onChange={(v) => onChange({ ...value, grossWeightKg: v === '' ? '' : Number(v) })}
|
|
||||||
/>
|
|
||||||
<NumberInput
|
|
||||||
label="Net weight (kg)"
|
|
||||||
min={0}
|
|
||||||
value={value.netWeightKg}
|
|
||||||
onChange={(v) => onChange({ ...value, netWeightKg: v === '' ? '' : Number(v) })}
|
|
||||||
/>
|
|
||||||
</Group>
|
|
||||||
<TextInput
|
<TextInput
|
||||||
label="Volume / dimensions"
|
label="Volume / dimensions"
|
||||||
value={value.volumeDimensions}
|
value={value.volumeDimensions}
|
||||||
@@ -650,11 +724,15 @@ function EligibleTab({
|
|||||||
location,
|
location,
|
||||||
enabled,
|
enabled,
|
||||||
onChanged,
|
onChanged,
|
||||||
|
focusedBookingId,
|
||||||
|
focusedBookingLabel,
|
||||||
}: {
|
}: {
|
||||||
direction: 'IMPORT' | 'EXPORT';
|
direction: 'IMPORT' | 'EXPORT';
|
||||||
location: Location;
|
location: Location;
|
||||||
enabled: boolean;
|
enabled: boolean;
|
||||||
onChanged?: () => void;
|
onChanged?: () => void;
|
||||||
|
focusedBookingId?: string;
|
||||||
|
focusedBookingLabel?: string;
|
||||||
}) {
|
}) {
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
const qc = useQueryClient();
|
const qc = useQueryClient();
|
||||||
@@ -664,7 +742,15 @@ function EligibleTab({
|
|||||||
enabled,
|
enabled,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
const rows = useMemo(() => allRows.filter((r) => r.direction === direction), [allRows, direction]);
|
const rows = useMemo(
|
||||||
|
() =>
|
||||||
|
allRows.filter(
|
||||||
|
(r) =>
|
||||||
|
r.direction === direction &&
|
||||||
|
(!focusedBookingId || r.id === focusedBookingId),
|
||||||
|
),
|
||||||
|
[allRows, direction, focusedBookingId],
|
||||||
|
);
|
||||||
const bulkReceive = useMutation(api.warehouses.bulkReceive.mutationOptions());
|
const bulkReceive = useMutation(api.warehouses.bulkReceive.mutationOptions());
|
||||||
const requestFirstMile = useMutation({
|
const requestFirstMile = useMutation({
|
||||||
mutationFn: (reference: string) => firstMileService.accept(reference),
|
mutationFn: (reference: string) => firstMileService.accept(reference),
|
||||||
@@ -766,6 +852,8 @@ function EligibleTab({
|
|||||||
[pendingReceiveIds, rows],
|
[pendingReceiveIds, rows],
|
||||||
);
|
);
|
||||||
const pendingHasFirstMile = pendingReceiveRows.some((row) => row.hasFirstMile);
|
const pendingHasFirstMile = pendingReceiveRows.some((row) => row.hasFirstMile);
|
||||||
|
const pendingUsesFirstMile =
|
||||||
|
pendingReceiveRows.length > 0 && pendingReceiveRows.every((row) => row.hasFirstMile);
|
||||||
|
|
||||||
const toggleAll = () =>
|
const toggleAll = () =>
|
||||||
setSelected(allSelected ? new Set() : new Set(selectableRows.map((r) => r.id)));
|
setSelected(allSelected ? new Set() : new Set(selectableRows.map((r) => r.id)));
|
||||||
@@ -788,6 +876,18 @@ function EligibleTab({
|
|||||||
title: `${r.receivedCount} received at ${direction === 'EXPORT' ? 'facility' : 'warehouse'}`,
|
title: `${r.receivedCount} received at ${direction === 'EXPORT' ? 'facility' : 'warehouse'}`,
|
||||||
description: r.results.find((item) => item.grnNumber)?.grnNumber ?? (r.skippedCount ? `${r.skippedCount} skipped` : undefined),
|
description: r.results.find((item) => item.grnNumber)?.grnNumber ?? (r.skippedCount ? `${r.skippedCount} skipped` : undefined),
|
||||||
});
|
});
|
||||||
|
const firstGrn = r.results.find((item) => item.inventoryId && item.grnNumber);
|
||||||
|
if (focusedBookingId && firstGrn?.inventoryId && firstGrn.grnNumber) {
|
||||||
|
const pdfWindow = window.open('', '_blank');
|
||||||
|
try {
|
||||||
|
const response = await warehouseService.downloadGrnDocument(firstGrn.inventoryId);
|
||||||
|
const opened = openPdfBlob(response.data, `grn-${firstGrn.grnNumber}.pdf`, pdfWindow);
|
||||||
|
toast({ title: opened ? 'GRN document opened' : 'GRN document downloaded' });
|
||||||
|
} catch (error) {
|
||||||
|
pdfWindow?.close();
|
||||||
|
toast({ variant: 'destructive', title: 'GRN document failed', description: extractErrorMessage(error) });
|
||||||
|
}
|
||||||
|
}
|
||||||
setSelected(new Set());
|
setSelected(new Set());
|
||||||
setTruckOpen(false);
|
setTruckOpen(false);
|
||||||
setPendingReceiveIds([]);
|
setPendingReceiveIds([]);
|
||||||
@@ -822,32 +922,65 @@ function EligibleTab({
|
|||||||
void receiveBookings(filteredIds);
|
void receiveBookings(filteredIds);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const hasFirstMileRows = selectedRows.some((row) => row.hasFirstMile);
|
||||||
|
const hasCustomerTruckRows = selectedRows.some((row) => !row.hasFirstMile);
|
||||||
|
if (hasFirstMileRows && hasCustomerTruckRows) {
|
||||||
|
toast({
|
||||||
|
variant: 'destructive',
|
||||||
|
title: 'Receive separately',
|
||||||
|
description: 'First-mile arrivals and customer-truck arrivals use different truck evidence. Select one group at a time.',
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
const { form, lockedFields, packagingFreightType: nextPackagingFreightType } = truckEntranceFromBookings(selectedRows);
|
const { form, lockedFields, packagingFreightType: nextPackagingFreightType } = truckEntranceFromBookings(selectedRows);
|
||||||
const totalContainerQuantity = selectedRows.reduce(
|
const totalContainerQuantity = selectedRows.reduce(
|
||||||
(sum, row) => sum + Number(row.containerQuantity ?? 0),
|
(sum, row) => sum + Number(row.containerQuantity ?? 0),
|
||||||
0,
|
0,
|
||||||
);
|
);
|
||||||
|
const usesFirstMile = selectedRows.length > 0 && selectedRows.every((row) => row.hasFirstMile);
|
||||||
|
const usesCustomerAssignedTruck =
|
||||||
|
selectedRows.length > 0 &&
|
||||||
|
selectedRows.every((row) => !row.hasFirstMile && Boolean(row.customerTruckAssignedAt));
|
||||||
const normalizedForm =
|
const normalizedForm =
|
||||||
nextPackagingFreightType === 'CONTAINER' && totalContainerQuantity > 0
|
nextPackagingFreightType === 'CONTAINER' && totalContainerQuantity > 0
|
||||||
? {
|
? {
|
||||||
...form,
|
...form,
|
||||||
unitCount: totalContainerQuantity,
|
unitCount: totalContainerQuantity,
|
||||||
}
|
}
|
||||||
: form;
|
: {
|
||||||
|
...form,
|
||||||
|
};
|
||||||
setPendingReceiveIds(filteredIds);
|
setPendingReceiveIds(filteredIds);
|
||||||
setReceivedAt(new Date().toISOString());
|
setReceivedAt(new Date().toISOString());
|
||||||
setTruckForm(normalizedForm);
|
setTruckForm(normalizedForm);
|
||||||
setLockedTruckFields({
|
setLockedTruckFields({
|
||||||
...lockedFields,
|
...lockedFields,
|
||||||
unitCount: nextPackagingFreightType === 'CONTAINER' && totalContainerQuantity > 0,
|
unitCount: nextPackagingFreightType === 'CONTAINER' && totalContainerQuantity > 0,
|
||||||
|
assignedEquipmentNumber: usesCustomerAssignedTruck
|
||||||
|
? lockedFields.assignedEquipmentNumber
|
||||||
|
: lockedFields.assignedEquipmentNumber,
|
||||||
|
truckPlateNumber: (usesFirstMile || usesCustomerAssignedTruck) && lockedFields.truckPlateNumber,
|
||||||
|
trailerPlateNumber: usesFirstMile && lockedFields.trailerPlateNumber,
|
||||||
|
driverName: (usesFirstMile || usesCustomerAssignedTruck) && lockedFields.driverName,
|
||||||
|
driverPhone: usesFirstMile && lockedFields.driverPhone,
|
||||||
|
driverLicenseNumber: usesFirstMile && lockedFields.driverLicenseNumber,
|
||||||
|
truckType: (usesFirstMile || usesCustomerAssignedTruck) && lockedFields.truckType,
|
||||||
});
|
});
|
||||||
setPackagingFreightType(nextPackagingFreightType);
|
setPackagingFreightType(nextPackagingFreightType);
|
||||||
setTruckOpen(true);
|
setTruckOpen(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
const receive = async () => {
|
const receive = async () => {
|
||||||
if (!truckForm.truckPlateNumber.trim() || !truckForm.driverName.trim() || !truckForm.driverPhone.trim() || truckForm.entranceTareWeightKg === '') {
|
if (!truckForm.truckPlateNumber.trim() || !truckForm.driverName.trim() || !truckForm.driverPhone.trim()) {
|
||||||
toast({ variant: 'destructive', title: 'Truck, driver and entrance tare weight are required' });
|
toast({ variant: 'destructive', title: 'Truck and driver information are required' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!pendingUsesFirstMile && truckForm.weighingRequired == null) {
|
||||||
|
toast({ variant: 'destructive', title: 'Select whether customer truck weighing is required' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (truckForm.weighingRequired && (truckForm.grossWeightKg === '' || truckForm.exitTareWeightKg === '')) {
|
||||||
|
toast({ variant: 'destructive', title: 'Gross weight and exit tare weight are required when weighing is Yes' });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await receiveBookings(pendingReceiveIds, toTruckEntrancePayload(truckForm));
|
await receiveBookings(pendingReceiveIds, toTruckEntrancePayload(truckForm));
|
||||||
@@ -906,7 +1039,9 @@ function EligibleTab({
|
|||||||
</Group>
|
</Group>
|
||||||
) : statusFilteredRows.length === 0 ? (
|
) : statusFilteredRows.length === 0 ? (
|
||||||
<Text c="dimmed" ta="center" py="lg" size="sm">
|
<Text c="dimmed" ta="center" py="lg" size="sm">
|
||||||
No eligible PAID {direction.toLowerCase()} bookings to receive.
|
{focusedBookingLabel
|
||||||
|
? `${focusedBookingLabel} is not eligible for warehouse receiving yet.`
|
||||||
|
: `No eligible PAID ${direction.toLowerCase()} bookings to receive.`}
|
||||||
</Text>
|
</Text>
|
||||||
) : (
|
) : (
|
||||||
<Table.ScrollContainer minWidth={1700}>
|
<Table.ScrollContainer minWidth={1700}>
|
||||||
@@ -1053,8 +1188,8 @@ function EligibleTab({
|
|||||||
<Stack gap="md">
|
<Stack gap="md">
|
||||||
<Alert icon={<Truck size={16} />} color={pendingHasFirstMile ? 'green' : 'blue'} variant="light">
|
<Alert icon={<Truck size={16} />} color={pendingHasFirstMile ? 'green' : 'blue'} variant="light">
|
||||||
<Text size="sm">
|
<Text size="sm">
|
||||||
{pendingHasFirstMile
|
{pendingUsesFirstMile
|
||||||
? 'Assigned first-mile truck and driver details are prefilled. Confirm or update the actual arrival details before GRN.'
|
? 'Received first-mile truck and driver details are pulled from the first-mile record. GRN uses booking cargo, quantity and weight.'
|
||||||
: 'Register the customer or third-party truck and driver before export receiving and GRN.'}
|
: 'Register the customer or third-party truck and driver before export receiving and GRN.'}
|
||||||
</Text>
|
</Text>
|
||||||
</Alert>
|
</Alert>
|
||||||
@@ -1109,6 +1244,7 @@ function EligibleTab({
|
|||||||
onChange={setTruckForm}
|
onChange={setTruckForm}
|
||||||
lockedFields={lockedTruckFields}
|
lockedFields={lockedTruckFields}
|
||||||
packagingFreightType={packagingFreightType}
|
packagingFreightType={packagingFreightType}
|
||||||
|
allowTruckWeighing={!pendingUsesFirstMile}
|
||||||
/>
|
/>
|
||||||
<Group justify="flex-end">
|
<Group justify="flex-end">
|
||||||
<Button variant="default" onClick={() => setTruckOpen(false)} disabled={bulkReceive.isPending}>
|
<Button variant="default" onClick={() => setTruckOpen(false)} disabled={bulkReceive.isPending}>
|
||||||
@@ -1611,14 +1747,59 @@ function LoadedExportTab({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Assigned bookings/items for an arrived import train (read-only detail view). */
|
const importLocationTypesForFreight = (freightType: string | null | undefined) => {
|
||||||
function ImportTrainDetailTable({ train }: { train: ImportTrain }) {
|
const normalized = (freightType ?? '').toUpperCase();
|
||||||
|
if (normalized === 'CONTAINER') {
|
||||||
|
return { yardTypes: ['CONTAINER_YARD', 'GENERAL_CARGO_YARD'], zoneTypes: ['CONTAINER_ZONE', 'GENERAL_CARGO_ZONE'] };
|
||||||
|
}
|
||||||
|
return { yardTypes: ['BULK_YARD', 'GENERAL_CARGO_YARD'], zoneTypes: ['BULK_ZONE', 'GENERAL_CARGO_ZONE'] };
|
||||||
|
};
|
||||||
|
|
||||||
|
const isImportContainerFreight = (freightType: string | null | undefined) =>
|
||||||
|
(freightType ?? '').toUpperCase() === 'CONTAINER';
|
||||||
|
|
||||||
|
const isImportUnloadPending = (item: ImportTrainItem) =>
|
||||||
|
!item.currentStatus || item.currentStatus === 'RECEIVED';
|
||||||
|
|
||||||
|
/** Assigned bookings/items for an arrived import train with per-booking unload locations. */
|
||||||
|
function ImportTrainDetailTable({
|
||||||
|
train,
|
||||||
|
warehouses,
|
||||||
|
yards,
|
||||||
|
zones,
|
||||||
|
assignments,
|
||||||
|
onAssignmentChange,
|
||||||
|
onReadyChange,
|
||||||
|
}: {
|
||||||
|
train: ImportTrain;
|
||||||
|
warehouses: Warehouse[];
|
||||||
|
yards: WarehouseYard[];
|
||||||
|
zones: WarehouseZone[];
|
||||||
|
assignments: Record<string, ImportUnloadAssignmentDraft>;
|
||||||
|
onAssignmentChange: (bookingId: string, draft: ImportUnloadAssignmentDraft) => void;
|
||||||
|
onReadyChange: (ready: boolean) => void;
|
||||||
|
}) {
|
||||||
const { data: items = [], isLoading } = useQuery(
|
const { data: items = [], isLoading } = useQuery(
|
||||||
api.warehouses.importTrainItems.queryOptions({
|
api.warehouses.importTrainItems.queryOptions({
|
||||||
input: { scheduleId: train.scheduleId },
|
input: { scheduleId: train.scheduleId },
|
||||||
enabled: Boolean(train.scheduleId),
|
enabled: Boolean(train.scheduleId),
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
const warehouseOptions = useMemo(
|
||||||
|
() => warehouses.map((warehouse) => ({ value: warehouse.id, label: `${warehouse.name} (${warehouse.code})` })),
|
||||||
|
[warehouses],
|
||||||
|
);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const pending = items.filter(isImportUnloadPending);
|
||||||
|
onReadyChange(
|
||||||
|
pending.length > 0 &&
|
||||||
|
pending.every((item) => {
|
||||||
|
const draft = assignments[item.bookingId];
|
||||||
|
return Boolean(draft?.warehouseId && draft.yardId && draft.zoneId);
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}, [assignments, items]);
|
||||||
|
|
||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
return (
|
return (
|
||||||
@@ -1648,6 +1829,9 @@ function ImportTrainDetailTable({ train }: { train: ImportTrain }) {
|
|||||||
<Table.Th>Cargo Type</Table.Th>
|
<Table.Th>Cargo Type</Table.Th>
|
||||||
<Table.Th>Weight</Table.Th>
|
<Table.Th>Weight</Table.Th>
|
||||||
<Table.Th>Arrival</Table.Th>
|
<Table.Th>Arrival</Table.Th>
|
||||||
|
<Table.Th>Warehouse</Table.Th>
|
||||||
|
<Table.Th>Yard</Table.Th>
|
||||||
|
<Table.Th>Zone</Table.Th>
|
||||||
<Table.Th>Inspection</Table.Th>
|
<Table.Th>Inspection</Table.Th>
|
||||||
<Table.Th>Current Status</Table.Th>
|
<Table.Th>Current Status</Table.Th>
|
||||||
<Table.Th>Last Mile</Table.Th>
|
<Table.Th>Last Mile</Table.Th>
|
||||||
@@ -1655,7 +1839,18 @@ function ImportTrainDetailTable({ train }: { train: ImportTrain }) {
|
|||||||
</Table.Tr>
|
</Table.Tr>
|
||||||
</Table.Thead>
|
</Table.Thead>
|
||||||
<Table.Tbody>
|
<Table.Tbody>
|
||||||
{items.map((it: ImportTrainItem) => (
|
{items.map((it: ImportTrainItem) => {
|
||||||
|
const draft = assignments[it.bookingId] ?? {};
|
||||||
|
const { yardTypes, zoneTypes } = importLocationTypesForFreight(it.freightType);
|
||||||
|
const yardOptions = yards
|
||||||
|
.filter((yard) => yard.warehouseId === draft.warehouseId && yardTypes.includes(yard.type))
|
||||||
|
.map((yard) => ({ value: yard.id, label: `${yard.name} (${yard.code})` }));
|
||||||
|
const zoneOptions = zones
|
||||||
|
.filter((zone) => zone.yardId === draft.yardId && zoneTypes.includes(zone.type))
|
||||||
|
.map((zone) => ({ value: zone.id, label: `${zone.name} (${zone.code})` }));
|
||||||
|
const pending = isImportUnloadPending(it);
|
||||||
|
|
||||||
|
return (
|
||||||
<Table.Tr key={`${it.bookingId}-${it.sequenceNo ?? 'wagon'}`}>
|
<Table.Tr key={`${it.bookingId}-${it.sequenceNo ?? 'wagon'}`}>
|
||||||
<Table.Td>
|
<Table.Td>
|
||||||
<Text size="xs" fw={600}>
|
<Text size="xs" fw={600}>
|
||||||
@@ -1676,6 +1871,41 @@ function ImportTrainDetailTable({ train }: { train: ImportTrain }) {
|
|||||||
<Table.Td>{it.cargoType ?? '—'}</Table.Td>
|
<Table.Td>{it.cargoType ?? '—'}</Table.Td>
|
||||||
<Table.Td>{formatNumber(Number(it.weight))}</Table.Td>
|
<Table.Td>{formatNumber(Number(it.weight))}</Table.Td>
|
||||||
<Table.Td>{formatDate(it.arrivalTime)}</Table.Td>
|
<Table.Td>{formatDate(it.arrivalTime)}</Table.Td>
|
||||||
|
<Table.Td>
|
||||||
|
<Select
|
||||||
|
placeholder="Warehouse"
|
||||||
|
data={warehouseOptions}
|
||||||
|
value={draft.warehouseId ?? null}
|
||||||
|
onChange={(value) => onAssignmentChange(it.bookingId, { warehouseId: value ?? undefined })}
|
||||||
|
searchable
|
||||||
|
disabled={!pending}
|
||||||
|
w={210}
|
||||||
|
/>
|
||||||
|
</Table.Td>
|
||||||
|
<Table.Td>
|
||||||
|
<Select
|
||||||
|
placeholder={isImportContainerFreight(it.freightType) ? 'Container yard' : 'Bulk yard'}
|
||||||
|
data={yardOptions}
|
||||||
|
value={draft.yardId ?? null}
|
||||||
|
onChange={(value) =>
|
||||||
|
onAssignmentChange(it.bookingId, { ...draft, yardId: value ?? undefined, zoneId: undefined })
|
||||||
|
}
|
||||||
|
searchable
|
||||||
|
disabled={!pending || !draft.warehouseId}
|
||||||
|
w={190}
|
||||||
|
/>
|
||||||
|
</Table.Td>
|
||||||
|
<Table.Td>
|
||||||
|
<Select
|
||||||
|
placeholder={isImportContainerFreight(it.freightType) ? 'Container zone' : 'Bulk zone'}
|
||||||
|
data={zoneOptions}
|
||||||
|
value={draft.zoneId ?? null}
|
||||||
|
onChange={(value) => onAssignmentChange(it.bookingId, { ...draft, zoneId: value ?? undefined })}
|
||||||
|
searchable
|
||||||
|
disabled={!pending || !draft.yardId}
|
||||||
|
w={190}
|
||||||
|
/>
|
||||||
|
</Table.Td>
|
||||||
<Table.Td>
|
<Table.Td>
|
||||||
<Badge size="xs" variant="light" color={it.inspectionStatus === 'PASSED' ? 'green' : 'gray'}>
|
<Badge size="xs" variant="light" color={it.inspectionStatus === 'PASSED' ? 'green' : 'gray'}>
|
||||||
{it.inspectionStatus ?? 'Not inspected'}
|
{it.inspectionStatus ?? 'Not inspected'}
|
||||||
@@ -1691,7 +1921,8 @@ function ImportTrainDetailTable({ train }: { train: ImportTrain }) {
|
|||||||
</Table.Td>
|
</Table.Td>
|
||||||
<Table.Td>{it.pickupOption}</Table.Td>
|
<Table.Td>{it.pickupOption}</Table.Td>
|
||||||
</Table.Tr>
|
</Table.Tr>
|
||||||
))}
|
);
|
||||||
|
})}
|
||||||
</Table.Tbody>
|
</Table.Tbody>
|
||||||
</Table>
|
</Table>
|
||||||
);
|
);
|
||||||
@@ -1715,13 +1946,42 @@ function ImportArriveQueueTab({
|
|||||||
const { data: trains = [], isLoading } = useQuery(
|
const { data: trains = [], isLoading } = useQuery(
|
||||||
api.warehouses.importArriveQueue.queryOptions({ enabled }),
|
api.warehouses.importArriveQueue.queryOptions({ enabled }),
|
||||||
);
|
);
|
||||||
|
const { data: warehouses = [], isLoading: warehousesLoading } = useQuery(
|
||||||
|
api.warehouses.list.queryOptions({ input: { filter: { status: 'ACTIVE' } }, enabled }),
|
||||||
|
);
|
||||||
|
const { data: yards = [] } = useAllWarehouseYards();
|
||||||
|
const { data: zones = [] } = useAllWarehouseZones();
|
||||||
const autoUnloadMutation = useMutation(
|
const autoUnloadMutation = useMutation(
|
||||||
api.warehouses.autoUnloadArrivedBookings.mutationOptions(),
|
api.warehouses.autoUnloadArrivedBookings.mutationOptions(),
|
||||||
);
|
);
|
||||||
const [openId, setOpenId] = useState<string | null>(null);
|
const [openId, setOpenId] = useState<string | null>(null);
|
||||||
const [busyId, setBusyId] = useState<string | null>(null);
|
const [busyId, setBusyId] = useState<string | null>(null);
|
||||||
|
const [assignmentsBySchedule, setAssignmentsBySchedule] = useState<
|
||||||
|
Record<string, Record<string, ImportUnloadAssignmentDraft>>
|
||||||
|
>({});
|
||||||
|
const [readyBySchedule, setReadyBySchedule] = useState<Record<string, boolean>>({});
|
||||||
|
|
||||||
const autoUnload = async (train: ImportTrain) => {
|
const autoUnload = async (train: ImportTrain) => {
|
||||||
|
const assignments = Object.entries(assignmentsBySchedule[train.scheduleId] ?? {})
|
||||||
|
.filter((entry): entry is [string, Required<ImportUnloadAssignmentDraft>] =>
|
||||||
|
Boolean(entry[1].warehouseId && entry[1].yardId && entry[1].zoneId),
|
||||||
|
)
|
||||||
|
.map(([bookingId, draft]) => ({
|
||||||
|
bookingId,
|
||||||
|
warehouseId: draft.warehouseId,
|
||||||
|
yardId: draft.yardId,
|
||||||
|
zoneId: draft.zoneId,
|
||||||
|
}));
|
||||||
|
|
||||||
|
if (!readyBySchedule[train.scheduleId] || assignments.length === 0) {
|
||||||
|
toast({
|
||||||
|
variant: 'destructive',
|
||||||
|
title: 'Assign locations',
|
||||||
|
description: 'Select warehouse, yard and zone for each pending booking before unloading.',
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (isFullyUnloaded(train)) {
|
if (isFullyUnloaded(train)) {
|
||||||
toast({
|
toast({
|
||||||
title: 'Already unloaded',
|
title: 'Already unloaded',
|
||||||
@@ -1732,7 +1992,7 @@ function ImportArriveQueueTab({
|
|||||||
|
|
||||||
setBusyId(train.scheduleId);
|
setBusyId(train.scheduleId);
|
||||||
try {
|
try {
|
||||||
const r = await autoUnloadMutation.mutateAsync(train.scheduleId);
|
const r = await autoUnloadMutation.mutateAsync({ scheduleId: train.scheduleId, assignments });
|
||||||
const alreadyUnloaded = r.unloadedCount === 0 && r.skippedCount > 0 && r.failedCount === 0;
|
const alreadyUnloaded = r.unloadedCount === 0 && r.skippedCount > 0 && r.failedCount === 0;
|
||||||
const firstReason = r.results.find((item) => item.reason)?.reason;
|
const firstReason = r.results.find((item) => item.reason)?.reason;
|
||||||
const extra = [
|
const extra = [
|
||||||
@@ -1831,7 +2091,7 @@ function ImportArriveQueueTab({
|
|||||||
color={fullyUnloaded ? 'gray' : 'indigo'}
|
color={fullyUnloaded ? 'gray' : 'indigo'}
|
||||||
leftSection={<Truck size={14} />}
|
leftSection={<Truck size={14} />}
|
||||||
loading={busyId === t.scheduleId}
|
loading={busyId === t.scheduleId}
|
||||||
disabled={fullyUnloaded || t.totalBookings === 0}
|
disabled={fullyUnloaded || t.totalBookings === 0 || !readyBySchedule[t.scheduleId] || warehousesLoading}
|
||||||
onClick={() => autoUnload(t)}
|
onClick={() => autoUnload(t)}
|
||||||
>
|
>
|
||||||
{fullyUnloaded ? 'Already Unloaded' : 'Auto Unload Arrived Bookings'}
|
{fullyUnloaded ? 'Already Unloaded' : 'Auto Unload Arrived Bookings'}
|
||||||
@@ -1842,7 +2102,25 @@ function ImportArriveQueueTab({
|
|||||||
{isOpen && (
|
{isOpen && (
|
||||||
<Table.Tr>
|
<Table.Tr>
|
||||||
<Table.Td colSpan={11} bg="var(--mantine-color-gray-0)">
|
<Table.Td colSpan={11} bg="var(--mantine-color-gray-0)">
|
||||||
<ImportTrainDetailTable train={t} />
|
<ImportTrainDetailTable
|
||||||
|
train={t}
|
||||||
|
warehouses={warehouses}
|
||||||
|
yards={yards}
|
||||||
|
zones={zones}
|
||||||
|
assignments={assignmentsBySchedule[t.scheduleId] ?? {}}
|
||||||
|
onAssignmentChange={(bookingId, draft) =>
|
||||||
|
setAssignmentsBySchedule((current) => ({
|
||||||
|
...current,
|
||||||
|
[t.scheduleId]: {
|
||||||
|
...(current[t.scheduleId] ?? {}),
|
||||||
|
[bookingId]: draft.warehouseId ? draft : {},
|
||||||
|
},
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
onReadyChange={(ready) =>
|
||||||
|
setReadyBySchedule((current) => ({ ...current, [t.scheduleId]: ready }))
|
||||||
|
}
|
||||||
|
/>
|
||||||
</Table.Td>
|
</Table.Td>
|
||||||
</Table.Tr>
|
</Table.Tr>
|
||||||
)}
|
)}
|
||||||
@@ -1934,6 +2212,11 @@ function ImportUnloadedQueueTab({ enabled }: { enabled: boolean }) {
|
|||||||
reference: row.bookingReference ?? row.bookingId,
|
reference: row.bookingReference ?? row.bookingId,
|
||||||
tradeDirection: 'IMPORT',
|
tradeDirection: 'IMPORT',
|
||||||
lastMileDeliveryAddress: row.lastMileRequested ? row.pickupOption : null,
|
lastMileDeliveryAddress: row.lastMileRequested ? row.pickupOption : null,
|
||||||
|
customerTruckPlateNumber: row.customerTruckPlateNumber,
|
||||||
|
customerTruckDriverName: row.customerTruckDriverName,
|
||||||
|
customerTruckType: row.customerTruckType,
|
||||||
|
customerTruckContainerNumber: row.customerTruckContainerNumber,
|
||||||
|
customerTruckAssignedAt: row.customerTruckAssignedAt,
|
||||||
}
|
}
|
||||||
: null,
|
: null,
|
||||||
}) as unknown as WarehouseInventoryItem;
|
}) as unknown as WarehouseInventoryItem;
|
||||||
@@ -2262,6 +2545,8 @@ interface WarehouseFlowWorkbenchProps {
|
|||||||
direction?: WarehouseFlowDirection;
|
direction?: WarehouseFlowDirection;
|
||||||
enabled?: boolean;
|
enabled?: boolean;
|
||||||
onChanged?: () => void;
|
onChanged?: () => void;
|
||||||
|
focusedBookingId?: string;
|
||||||
|
focusedBookingLabel?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
function WarehouseQueueTabs<TValue extends string>({
|
function WarehouseQueueTabs<TValue extends string>({
|
||||||
@@ -2481,10 +2766,14 @@ function ExportWarehouseTabs({
|
|||||||
enabled,
|
enabled,
|
||||||
location,
|
location,
|
||||||
onChanged,
|
onChanged,
|
||||||
|
focusedBookingId,
|
||||||
|
focusedBookingLabel,
|
||||||
}: {
|
}: {
|
||||||
enabled: boolean;
|
enabled: boolean;
|
||||||
location: Location;
|
location: Location;
|
||||||
onChanged?: () => void;
|
onChanged?: () => void;
|
||||||
|
focusedBookingId?: string;
|
||||||
|
focusedBookingLabel?: string;
|
||||||
}) {
|
}) {
|
||||||
const [activeTab, setActiveTab] = useState<ExportWarehouseTab>('receive-queue');
|
const [activeTab, setActiveTab] = useState<ExportWarehouseTab>('receive-queue');
|
||||||
const { data: eligibleRows = [] } = useQuery(
|
const { data: eligibleRows = [] } = useQuery(
|
||||||
@@ -2543,7 +2832,14 @@ function ExportWarehouseTabs({
|
|||||||
<WarehouseQueueTabs value={activeTab} onChange={setActiveTab} tabs={tabs} />
|
<WarehouseQueueTabs value={activeTab} onChange={setActiveTab} tabs={tabs} />
|
||||||
|
|
||||||
{activeTab === 'receive-queue' && (
|
{activeTab === 'receive-queue' && (
|
||||||
<EligibleTab direction="EXPORT" location={location} enabled={enabled} onChanged={onChanged} />
|
<EligibleTab
|
||||||
|
direction="EXPORT"
|
||||||
|
location={location}
|
||||||
|
enabled={enabled}
|
||||||
|
onChanged={onChanged}
|
||||||
|
focusedBookingId={focusedBookingId}
|
||||||
|
focusedBookingLabel={focusedBookingLabel}
|
||||||
|
/>
|
||||||
)}
|
)}
|
||||||
{activeTab === 'received' && (
|
{activeTab === 'received' && (
|
||||||
<ExportReceivedTab enabled={enabled} onChanged={onChanged} />
|
<ExportReceivedTab enabled={enabled} onChanged={onChanged} />
|
||||||
@@ -2568,6 +2864,8 @@ export function WarehouseFlowWorkbench({
|
|||||||
direction = 'BOTH',
|
direction = 'BOTH',
|
||||||
enabled = true,
|
enabled = true,
|
||||||
onChanged,
|
onChanged,
|
||||||
|
focusedBookingId,
|
||||||
|
focusedBookingLabel,
|
||||||
}: WarehouseFlowWorkbenchProps) {
|
}: WarehouseFlowWorkbenchProps) {
|
||||||
const [location, setLocation] = useState<Location>({ warehouseId: '', yardId: '', zoneId: '' });
|
const [location, setLocation] = useState<Location>({ warehouseId: '', yardId: '', zoneId: '' });
|
||||||
const [tab, setTab] = useState<Exclude<WarehouseFlowDirection, 'BOTH'>>(
|
const [tab, setTab] = useState<Exclude<WarehouseFlowDirection, 'BOTH'>>(
|
||||||
@@ -2600,24 +2898,42 @@ export function WarehouseFlowWorkbench({
|
|||||||
<ImportWarehouseTabs enabled={enabled} onChanged={onChanged} />
|
<ImportWarehouseTabs enabled={enabled} onChanged={onChanged} />
|
||||||
</Tabs.Panel>
|
</Tabs.Panel>
|
||||||
<Tabs.Panel value="EXPORT">
|
<Tabs.Panel value="EXPORT">
|
||||||
<ExportWarehouseTabs enabled={enabled} location={location} onChanged={onChanged} />
|
<ExportWarehouseTabs
|
||||||
|
enabled={enabled}
|
||||||
|
location={location}
|
||||||
|
onChanged={onChanged}
|
||||||
|
focusedBookingId={focusedBookingId}
|
||||||
|
focusedBookingLabel={focusedBookingLabel}
|
||||||
|
/>
|
||||||
</Tabs.Panel>
|
</Tabs.Panel>
|
||||||
</Tabs>
|
</Tabs>
|
||||||
) : activeDirection === 'IMPORT' ? (
|
) : activeDirection === 'IMPORT' ? (
|
||||||
<ImportWarehouseTabs enabled={enabled} onChanged={onChanged} />
|
<ImportWarehouseTabs enabled={enabled} onChanged={onChanged} />
|
||||||
) : (
|
) : (
|
||||||
<ExportWarehouseTabs enabled={enabled} location={location} onChanged={onChanged} />
|
<ExportWarehouseTabs
|
||||||
|
enabled={enabled}
|
||||||
|
location={location}
|
||||||
|
onChanged={onChanged}
|
||||||
|
focusedBookingId={focusedBookingId}
|
||||||
|
focusedBookingLabel={focusedBookingLabel}
|
||||||
|
/>
|
||||||
)}
|
)}
|
||||||
</Stack>
|
</Stack>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** New bulk Receive: Import / Export tabs with eligible PAID bookings. */
|
/** New bulk Receive: Import / Export tabs with eligible PAID bookings. */
|
||||||
function BulkReceiveModal({ opened, onClose, onReceived }: ReceiveInventoryModalProps) {
|
function BulkReceiveModal({ opened, onClose, onReceived, bookingId, bookingLabel, direction = 'BOTH' }: ReceiveInventoryModalProps) {
|
||||||
return (
|
return (
|
||||||
<Modal opened={opened} onClose={onClose} title="Receive at warehouse" centered size="80rem">
|
<Modal opened={opened} onClose={onClose} title="Receive at warehouse" centered size="80rem">
|
||||||
<Stack gap="md">
|
<Stack gap="md">
|
||||||
<WarehouseFlowWorkbench enabled={opened} direction="BOTH" onChanged={onReceived} />
|
<WarehouseFlowWorkbench
|
||||||
|
enabled={opened}
|
||||||
|
direction={direction}
|
||||||
|
onChanged={onReceived}
|
||||||
|
focusedBookingId={bookingId}
|
||||||
|
focusedBookingLabel={bookingLabel}
|
||||||
|
/>
|
||||||
|
|
||||||
<Group justify="flex-end" mt="sm">
|
<Group justify="flex-end" mt="sm">
|
||||||
<Button variant="default" onClick={onClose}>
|
<Button variant="default" onClick={onClose}>
|
||||||
@@ -2763,5 +3079,5 @@ function SingleBookingReceiveModal({
|
|||||||
|
|
||||||
export function ReceiveInventoryModal(props: ReceiveInventoryModalProps) {
|
export function ReceiveInventoryModal(props: ReceiveInventoryModalProps) {
|
||||||
// Locked to a booking → legacy single receive; otherwise the Import/Export bulk flow.
|
// Locked to a booking → legacy single receive; otherwise the Import/Export bulk flow.
|
||||||
return props.bookingId ? <SingleBookingReceiveModal {...props} /> : <BulkReceiveModal {...props} />;
|
return props.bookingId && props.mode !== 'bulk' ? <SingleBookingReceiveModal {...props} /> : <BulkReceiveModal {...props} />;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,17 @@ interface ReleaseOrderModalProps {
|
|||||||
opened: boolean;
|
opened: boolean;
|
||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
item: WarehouseInventoryItem | null;
|
item: WarehouseInventoryItem | null;
|
||||||
|
truckPrefill?: ReleaseOrderTruckPrefill | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ReleaseOrderTruckPrefill {
|
||||||
|
truckPlateNumber?: string | null;
|
||||||
|
trailerPlateNumber?: string | null;
|
||||||
|
driverName?: string | null;
|
||||||
|
driverLicense?: string | null;
|
||||||
|
driverPhone?: string | null;
|
||||||
|
truckType?: string | null;
|
||||||
|
containerNumber?: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const REGISTERED_FIRST_LAST_MILE_TRUCKS = [
|
const REGISTERED_FIRST_LAST_MILE_TRUCKS = [
|
||||||
@@ -82,6 +93,9 @@ const splitContainerNumbers = (value: string | null | undefined) =>
|
|||||||
const getItemContainerNumber = (item: WarehouseInventoryItem | null) =>
|
const getItemContainerNumber = (item: WarehouseInventoryItem | null) =>
|
||||||
(item as (WarehouseInventoryItem & { containerNumber?: string | null }) | null)?.containerNumber ?? '';
|
(item as (WarehouseInventoryItem & { containerNumber?: string | null }) | null)?.containerNumber ?? '';
|
||||||
|
|
||||||
|
const assignedTruckValue = (item: WarehouseInventoryItem | null, key: keyof NonNullable<WarehouseInventoryItem['booking']>) =>
|
||||||
|
item?.booking?.[key] == null ? '' : String(item.booking[key]);
|
||||||
|
|
||||||
const isContainerInventory = (item: WarehouseInventoryItem | null, containerCount: number) => {
|
const isContainerInventory = (item: WarehouseInventoryItem | null, containerCount: number) => {
|
||||||
const freightType = (item as (WarehouseInventoryItem & { booking?: { freightType?: string | null } | null }) | null)
|
const freightType = (item as (WarehouseInventoryItem & { booking?: { freightType?: string | null } | null }) | null)
|
||||||
?.booking?.freightType;
|
?.booking?.freightType;
|
||||||
@@ -117,7 +131,7 @@ const parseInspectionNote = (notes: string | null | undefined) => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export function ReleaseOrderModal({ opened, onClose, item }: ReleaseOrderModalProps) {
|
export function ReleaseOrderModal({ opened, onClose, item, truckPrefill }: ReleaseOrderModalProps) {
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
const releaseMutation = useMutation(api.warehouses.release.mutationOptions());
|
const releaseMutation = useMutation(api.warehouses.release.mutationOptions());
|
||||||
const [reference, setReference] = useState('');
|
const [reference, setReference] = useState('');
|
||||||
@@ -138,25 +152,34 @@ export function ReleaseOrderModal({ opened, onClose, item }: ReleaseOrderModalPr
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (opened) {
|
if (opened) {
|
||||||
const inspection = parseInspectionNote(item?.notes);
|
const inspection = parseInspectionNote(item?.notes);
|
||||||
|
const assignedTruckPlate = assignedTruckValue(item, 'customerTruckPlateNumber');
|
||||||
|
const assignedDriverName = assignedTruckValue(item, 'customerTruckDriverName');
|
||||||
|
const assignedTruckType = assignedTruckValue(item, 'customerTruckType');
|
||||||
|
const assignedContainerNumber = assignedTruckValue(item, 'customerTruckContainerNumber');
|
||||||
|
const prefillContainerNumber = truckPrefill?.containerNumber ?? '';
|
||||||
setReference(item?.releaseOrderReference ?? generateReleaseReference(item));
|
setReference(item?.releaseOrderReference ?? generateReleaseReference(item));
|
||||||
setTruckPlateNumber(inspection.truckPlateNumber);
|
setTruckPlateNumber(inspection.truckPlateNumber || truckPrefill?.truckPlateNumber || assignedTruckPlate || '');
|
||||||
setTrailerPlateNumber(inspection.trailerPlateNumber);
|
setTrailerPlateNumber(inspection.trailerPlateNumber || truckPrefill?.trailerPlateNumber || '');
|
||||||
setDriverName(inspection.driverName);
|
setDriverName(inspection.driverName || truckPrefill?.driverName || assignedDriverName || '');
|
||||||
setDriverLicense(inspection.driverLicense);
|
setDriverLicense(inspection.driverLicense || truckPrefill?.driverLicense || '');
|
||||||
setDriverPhone(inspection.driverPhone);
|
setDriverPhone(inspection.driverPhone || truckPrefill?.driverPhone || '');
|
||||||
setTruckType(inspection.truckType);
|
setTruckType(inspection.truckType || truckPrefill?.truckType || assignedTruckType || '');
|
||||||
setContainerNumbers(initialContainerNumbers(item, inspection.containerNumber));
|
setContainerNumbers(initialContainerNumbers(item, inspection.containerNumber || prefillContainerNumber || assignedContainerNumber));
|
||||||
setGateInTime(inspection.gateInTime);
|
setGateInTime(inspection.gateInTime);
|
||||||
setTareWeight(inspection.tareWeight);
|
setTareWeight(inspection.tareWeight);
|
||||||
setGrossWeight(inspection.grossWeight);
|
setGrossWeight(inspection.grossWeight);
|
||||||
setNetWeight(item?.weight == null ? inspection.netWeight : Number(item.weight));
|
setNetWeight(item?.weight == null ? inspection.netWeight : Number(item.weight));
|
||||||
setGateOutTime(inspection.gateOutTime);
|
setGateOutTime(inspection.gateOutTime);
|
||||||
}
|
}
|
||||||
}, [opened, item]);
|
}, [opened, item, truckPrefill]);
|
||||||
|
|
||||||
const savedInspection = parseInspectionNote(item?.notes);
|
const savedInspection = parseInspectionNote(item?.notes);
|
||||||
const isExitStep = savedInspection.tareWeight !== '';
|
const isExitStep = savedInspection.tareWeight !== '';
|
||||||
const isEntranceLocked = isExitStep;
|
const isEntranceLocked = isExitStep;
|
||||||
|
const isCustomerAssignedTruck = Boolean(item?.booking?.customerTruckAssignedAt);
|
||||||
|
const hasLastMileTruckPrefill = Boolean(truckPrefill?.truckPlateNumber || truckPrefill?.trailerPlateNumber);
|
||||||
|
const isTruckIdentityLocked = isEntranceLocked || isCustomerAssignedTruck || hasLastMileTruckPrefill;
|
||||||
|
const isDriverNameLocked = isEntranceLocked || isCustomerAssignedTruck || Boolean(truckPrefill?.driverName);
|
||||||
const systemNetWeight = item?.weight == null ? netWeight : Number(item.weight);
|
const systemNetWeight = item?.weight == null ? netWeight : Number(item.weight);
|
||||||
const computedNetWeight =
|
const computedNetWeight =
|
||||||
tareWeight !== '' && grossWeight !== '' ? Number((Number(grossWeight) - Number(tareWeight)).toFixed(3)) : null;
|
tareWeight !== '' && grossWeight !== '' ? Number((Number(grossWeight) - Number(tareWeight)).toFixed(3)) : null;
|
||||||
@@ -269,7 +292,7 @@ export function ReleaseOrderModal({ opened, onClose, item }: ReleaseOrderModalPr
|
|||||||
searchable
|
searchable
|
||||||
clearable
|
clearable
|
||||||
data={REGISTERED_FIRST_LAST_MILE_TRUCKS}
|
data={REGISTERED_FIRST_LAST_MILE_TRUCKS}
|
||||||
disabled={isEntranceLocked}
|
disabled={isTruckIdentityLocked}
|
||||||
value={REGISTERED_FIRST_LAST_MILE_TRUCKS.some((truck) => truck.value === truckPlateNumber) ? truckPlateNumber : null}
|
value={REGISTERED_FIRST_LAST_MILE_TRUCKS.some((truck) => truck.value === truckPlateNumber) ? truckPlateNumber : null}
|
||||||
onChange={(value) => {
|
onChange={(value) => {
|
||||||
const truck = REGISTERED_FIRST_LAST_MILE_TRUCKS.find((row) => row.value === value);
|
const truck = REGISTERED_FIRST_LAST_MILE_TRUCKS.find((row) => row.value === value);
|
||||||
@@ -283,7 +306,7 @@ export function ReleaseOrderModal({ opened, onClose, item }: ReleaseOrderModalPr
|
|||||||
required
|
required
|
||||||
value={truckPlateNumber}
|
value={truckPlateNumber}
|
||||||
onChange={(e) => setTruckPlateNumber(e.currentTarget.value)}
|
onChange={(e) => setTruckPlateNumber(e.currentTarget.value)}
|
||||||
readOnly={isEntranceLocked}
|
readOnly={isTruckIdentityLocked}
|
||||||
/>
|
/>
|
||||||
<TextInput
|
<TextInput
|
||||||
label="Trailer plate number"
|
label="Trailer plate number"
|
||||||
@@ -293,12 +316,12 @@ export function ReleaseOrderModal({ opened, onClose, item }: ReleaseOrderModalPr
|
|||||||
/>
|
/>
|
||||||
</Group>
|
</Group>
|
||||||
<Group grow>
|
<Group grow>
|
||||||
<TextInput label="Driver name" required value={driverName} onChange={(e) => setDriverName(e.currentTarget.value)} readOnly={isEntranceLocked} />
|
<TextInput label="Driver name" required value={driverName} onChange={(e) => setDriverName(e.currentTarget.value)} readOnly={isDriverNameLocked} />
|
||||||
<TextInput label="Driver license" value={driverLicense} onChange={(e) => setDriverLicense(e.currentTarget.value)} readOnly={isEntranceLocked} />
|
<TextInput label="Driver license" value={driverLicense} onChange={(e) => setDriverLicense(e.currentTarget.value)} readOnly={isEntranceLocked} />
|
||||||
</Group>
|
</Group>
|
||||||
<Group grow>
|
<Group grow>
|
||||||
<TextInput label="Driver phone" value={driverPhone} onChange={(e) => setDriverPhone(e.currentTarget.value)} readOnly={isEntranceLocked} />
|
<TextInput label="Driver phone" value={driverPhone} onChange={(e) => setDriverPhone(e.currentTarget.value)} readOnly={isEntranceLocked} />
|
||||||
<TextInput label="Truck type" value={truckType} onChange={(e) => setTruckType(e.currentTarget.value)} readOnly={isEntranceLocked} />
|
<TextInput label="Truck type" value={truckType} onChange={(e) => setTruckType(e.currentTarget.value)} readOnly={isTruckIdentityLocked} />
|
||||||
</Group>
|
</Group>
|
||||||
<Group grow>
|
<Group grow>
|
||||||
<Stack gap={6}>
|
<Stack gap={6}>
|
||||||
@@ -313,7 +336,7 @@ export function ReleaseOrderModal({ opened, onClose, item }: ReleaseOrderModalPr
|
|||||||
numbers.map((number, numberIndex) => (numberIndex === index ? e.currentTarget.value : number)),
|
numbers.map((number, numberIndex) => (numberIndex === index ? e.currentTarget.value : number)),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
readOnly={isEntranceLocked}
|
readOnly={isTruckIdentityLocked}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</SimpleGrid>
|
</SimpleGrid>
|
||||||
|
|||||||
@@ -475,6 +475,7 @@ export const URL_CONSTANTS = {
|
|||||||
RECEIPT: (id: string) => `/warehouse-fee-invoices/${id}/receipt`,
|
RECEIPT: (id: string) => `/warehouse-fee-invoices/${id}/receipt`,
|
||||||
CANCEL: (id: string) => `/warehouse-fee-invoices/${id}/cancel`,
|
CANCEL: (id: string) => `/warehouse-fee-invoices/${id}/cancel`,
|
||||||
PAY: (id: string) => `/warehouse-fee-invoices/${id}/pay`,
|
PAY: (id: string) => `/warehouse-fee-invoices/${id}/pay`,
|
||||||
|
PAY_ONLINE: (id: string) => `/warehouse-fee-invoices/${id}/pay-online`,
|
||||||
GENERATE: (inventoryId: string) => `/warehouse-inventory/${inventoryId}/generate-fee-invoice`,
|
GENERATE: (inventoryId: string) => `/warehouse-inventory/${inventoryId}/generate-fee-invoice`,
|
||||||
FOR_INVENTORY: (inventoryId: string) => `/warehouse-inventory/${inventoryId}/fee-invoices`,
|
FOR_INVENTORY: (inventoryId: string) => `/warehouse-inventory/${inventoryId}/fee-invoices`,
|
||||||
FOR_BOOKING: (bookingId: string) => `/bookings/${bookingId}/warehouse-fee-invoices`,
|
FOR_BOOKING: (bookingId: string) => `/bookings/${bookingId}/warehouse-fee-invoices`,
|
||||||
|
|||||||
@@ -280,7 +280,13 @@ export function useImportTrainItems(scheduleId?: string) {
|
|||||||
|
|
||||||
/** Unload all eligible assigned bookings of an ARRIVED import train (→ UNLOADED). */
|
/** Unload all eligible assigned bookings of an ARRIVED import train (→ UNLOADED). */
|
||||||
export const useAutoUnloadArrivedBookings = () =>
|
export const useAutoUnloadArrivedBookings = () =>
|
||||||
useInventoryMutation((scheduleId: string) => warehouseService.autoUnloadArrivedBookings(scheduleId));
|
useInventoryMutation((payload: {
|
||||||
|
scheduleId: string;
|
||||||
|
warehouseId?: string;
|
||||||
|
assignments?: { bookingId: string; warehouseId: string; yardId: string; zoneId: string }[];
|
||||||
|
}) =>
|
||||||
|
warehouseService.autoUnloadArrivedBookings(payload),
|
||||||
|
);
|
||||||
|
|
||||||
/** Arrived EXPORT trains at Djibouti-side ports. Read-only. */
|
/** Arrived EXPORT trains at Djibouti-side ports. Read-only. */
|
||||||
export function useExportDjiboutiArrivalQueue(enabled = true) {
|
export function useExportDjiboutiArrivalQueue(enabled = true) {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import {
|
|||||||
ChevronRight,
|
ChevronRight,
|
||||||
Eye,
|
Eye,
|
||||||
MoreHorizontal,
|
MoreHorizontal,
|
||||||
|
PackageCheck,
|
||||||
Printer,
|
Printer,
|
||||||
RefreshCw,
|
RefreshCw,
|
||||||
Ruler,
|
Ruler,
|
||||||
@@ -35,6 +36,7 @@ import {
|
|||||||
|
|
||||||
import { ruleEngineTable } from "@/components/ruleEngine/ruleEngineStyles";
|
import { ruleEngineTable } from "@/components/ruleEngine/ruleEngineStyles";
|
||||||
import { FirstMileContainerAllocationTable } from "@/components/FirstMileContainerAllocationTable";
|
import { FirstMileContainerAllocationTable } from "@/components/FirstMileContainerAllocationTable";
|
||||||
|
import { ReceiveInventoryModal } from "@/components/warehouses/ReceiveInventoryModal";
|
||||||
import { QUERY_KEYS } from "@/constants/QUERY_KEYS";
|
import { QUERY_KEYS } from "@/constants/QUERY_KEYS";
|
||||||
import { useToast } from "@/hooks/use-toast";
|
import { useToast } from "@/hooks/use-toast";
|
||||||
import {
|
import {
|
||||||
@@ -338,6 +340,8 @@ const FirstMilePage = () => {
|
|||||||
const [distanceValue, setDistanceValue] = useState("");
|
const [distanceValue, setDistanceValue] = useState("");
|
||||||
const [invoiceOpen, setInvoiceOpen] = useState(false);
|
const [invoiceOpen, setInvoiceOpen] = useState(false);
|
||||||
const [invoiceRecord, setInvoiceRecord] = useState<FirstMileRecord | null>(null);
|
const [invoiceRecord, setInvoiceRecord] = useState<FirstMileRecord | null>(null);
|
||||||
|
const [warehouseReceiveOpen, setWarehouseReceiveOpen] = useState(false);
|
||||||
|
const [warehouseReceiveRecord, setWarehouseReceiveRecord] = useState<FirstMileRecord | null>(null);
|
||||||
|
|
||||||
const [containerAllocationOpen, setContainerAllocationOpen] = useState(false);
|
const [containerAllocationOpen, setContainerAllocationOpen] = useState(false);
|
||||||
const [containerAllocationFirstMileId, setContainerAllocationFirstMileId] = useState<string | null>(null);
|
const [containerAllocationFirstMileId, setContainerAllocationFirstMileId] = useState<string | null>(null);
|
||||||
@@ -527,6 +531,16 @@ const FirstMilePage = () => {
|
|||||||
setInvoiceRecord(null);
|
setInvoiceRecord(null);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const openWarehouseReceive = (record: FirstMileRecord) => {
|
||||||
|
setWarehouseReceiveRecord(record);
|
||||||
|
setWarehouseReceiveOpen(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
const closeWarehouseReceive = () => {
|
||||||
|
setWarehouseReceiveOpen(false);
|
||||||
|
setWarehouseReceiveRecord(null);
|
||||||
|
};
|
||||||
|
|
||||||
const openContainerAllocation = (firstMileId: string) => {
|
const openContainerAllocation = (firstMileId: string) => {
|
||||||
setContainerAllocationFirstMileId(firstMileId);
|
setContainerAllocationFirstMileId(firstMileId);
|
||||||
setContainerAllocationOpen(true);
|
setContainerAllocationOpen(true);
|
||||||
@@ -829,6 +843,7 @@ const FirstMilePage = () => {
|
|||||||
const assigned = isAssigned(row.original);
|
const assigned = isAssigned(row.original);
|
||||||
const nextStatus = NEXT_STATUS[row.original.status];
|
const nextStatus = NEXT_STATUS[row.original.status];
|
||||||
const canPrint = row.original.status !== "PAYMENT_PENDING";
|
const canPrint = row.original.status !== "PAYMENT_PENDING";
|
||||||
|
const canReceiveToWarehouse = row.original.status === "RECEIVED_TO_PORT";
|
||||||
return (
|
return (
|
||||||
<Group gap={4} justify="flex-end" wrap="nowrap">
|
<Group gap={4} justify="flex-end" wrap="nowrap">
|
||||||
<Menu position="bottom-end" width={200} withinPortal>
|
<Menu position="bottom-end" width={200} withinPortal>
|
||||||
@@ -867,6 +882,13 @@ const FirstMilePage = () => {
|
|||||||
>
|
>
|
||||||
View detail
|
View detail
|
||||||
</Menu.Item>
|
</Menu.Item>
|
||||||
|
<Menu.Item
|
||||||
|
leftSection={<PackageCheck size={15} />}
|
||||||
|
disabled={!canReceiveToWarehouse}
|
||||||
|
onClick={() => openWarehouseReceive(row.original)}
|
||||||
|
>
|
||||||
|
Receive to warehouse
|
||||||
|
</Menu.Item>
|
||||||
<Menu.Item
|
<Menu.Item
|
||||||
leftSection={<Ruler size={15} />}
|
leftSection={<Ruler size={15} />}
|
||||||
onClick={() => openDistance(row.original.id)}
|
onClick={() => openDistance(row.original.id)}
|
||||||
@@ -1055,6 +1077,19 @@ const FirstMilePage = () => {
|
|||||||
</Stack>
|
</Stack>
|
||||||
</Modal>
|
</Modal>
|
||||||
|
|
||||||
|
<ReceiveInventoryModal
|
||||||
|
opened={warehouseReceiveOpen}
|
||||||
|
onClose={closeWarehouseReceive}
|
||||||
|
mode="bulk"
|
||||||
|
direction="EXPORT"
|
||||||
|
bookingId={warehouseReceiveRecord?.bookingId}
|
||||||
|
bookingLabel={warehouseReceiveRecord ? bookingRef(warehouseReceiveRecord) : undefined}
|
||||||
|
onReceived={() => {
|
||||||
|
void qc.invalidateQueries({ queryKey: QUERY_KEYS.FIRST_MILE.list() });
|
||||||
|
closeWarehouseReceive();
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
{/* Accept Booking modal — step 1: booking list, step 2: details + vehicle */}
|
{/* Accept Booking modal — step 1: booking list, step 2: details + vehicle */}
|
||||||
<Modal
|
<Modal
|
||||||
opened={acceptOpen}
|
opened={acceptOpen}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ import {
|
|||||||
TextInput,
|
TextInput,
|
||||||
UnstyledButton,
|
UnstyledButton,
|
||||||
} from "@mantine/core";
|
} from "@mantine/core";
|
||||||
import type { ArrivalQueueItem } from "@/types/warehouse";
|
import type { ArrivalQueueItem, ImportUnloadedItem, WarehouseInventoryItem } from "@/types/warehouse";
|
||||||
import { warehouseService } from "@/services/warehouse.service";
|
import { warehouseService } from "@/services/warehouse.service";
|
||||||
|
|
||||||
import { ruleEngineTable } from "@/components/ruleEngine/ruleEngineStyles";
|
import { ruleEngineTable } from "@/components/ruleEngine/ruleEngineStyles";
|
||||||
@@ -44,8 +44,10 @@ import {
|
|||||||
lastMileService,
|
lastMileService,
|
||||||
} from "@/services/last-mile.service";
|
} from "@/services/last-mile.service";
|
||||||
import { vehiclesService } from "@/services/vehicles.service";
|
import { vehiclesService } from "@/services/vehicles.service";
|
||||||
|
import { driversService, type Driver } from "@/services/drivers.service";
|
||||||
import { ratesService } from "@/services/rates.service";
|
import { ratesService } from "@/services/rates.service";
|
||||||
import { LastMileContainerAllocationTable, type LastMileContainerRow } from "@/components/LastMileContainerAllocationTable";
|
import { LastMileContainerAllocationTable, type LastMileContainerRow } from "@/components/LastMileContainerAllocationTable";
|
||||||
|
import { ReleaseOrderModal, type ReleaseOrderTruckPrefill } from "@/components/warehouses/ReleaseOrderModal";
|
||||||
import { api } from "@/auth/http";
|
import { api } from "@/auth/http";
|
||||||
|
|
||||||
const formatPrice = (amount: number) =>
|
const formatPrice = (amount: number) =>
|
||||||
@@ -110,6 +112,59 @@ const requestedDate = (r: LastMileRecord) => {
|
|||||||
const serviceTypeName = (r: LastMileRecord) =>
|
const serviceTypeName = (r: LastMileRecord) =>
|
||||||
r.booking?.serviceType?.label ?? r.booking?.serviceType?.name ?? "—";
|
r.booking?.serviceType?.label ?? r.booking?.serviceType?.name ?? "—";
|
||||||
|
|
||||||
|
const toReleaseInventoryItem = (row: ImportUnloadedItem): WarehouseInventoryItem =>
|
||||||
|
({
|
||||||
|
id: row.id,
|
||||||
|
bookingId: row.bookingId,
|
||||||
|
quantity: 1,
|
||||||
|
weight: Number(row.weight) || 0,
|
||||||
|
grnNumber: row.grnNumber,
|
||||||
|
status: row.currentStatus,
|
||||||
|
arrivedAt: row.arrivalTime,
|
||||||
|
unloadedAt: row.arrivalTime,
|
||||||
|
inspectionStatus: row.inspectionStatus,
|
||||||
|
releaseDate: row.releaseDate,
|
||||||
|
releaseOrderReference: row.releaseOrderReference,
|
||||||
|
handoverDocumentReference: row.handoverDocumentReference,
|
||||||
|
handoverDocumentDate: row.handoverDocumentDate,
|
||||||
|
deliveredAt: row.deliveredAt,
|
||||||
|
booking: row.bookingId
|
||||||
|
? {
|
||||||
|
id: row.bookingId,
|
||||||
|
reference: row.bookingReference ?? row.bookingId,
|
||||||
|
tradeDirection: "IMPORT",
|
||||||
|
lastMileDeliveryAddress: row.lastMileRequested ? row.pickupOption : null,
|
||||||
|
customerTruckPlateNumber: row.customerTruckPlateNumber,
|
||||||
|
customerTruckDriverName: row.customerTruckDriverName,
|
||||||
|
customerTruckType: row.customerTruckType,
|
||||||
|
customerTruckContainerNumber: row.customerTruckContainerNumber,
|
||||||
|
customerTruckAssignedAt: row.customerTruckAssignedAt,
|
||||||
|
}
|
||||||
|
: null,
|
||||||
|
}) as unknown as WarehouseInventoryItem;
|
||||||
|
|
||||||
|
const releasePrefillFromLastMile = (
|
||||||
|
record: LastMileRecord,
|
||||||
|
row?: ImportUnloadedItem | null,
|
||||||
|
driversById?: Map<string, Driver>,
|
||||||
|
): ReleaseOrderTruckPrefill => {
|
||||||
|
const vehicle = record.vehicle;
|
||||||
|
const truckType = [vehicle?.manufacturer, vehicle?.model].filter(Boolean).join(" ").trim();
|
||||||
|
const assignedDriver = vehicle?.assignedDriverId ? driversById?.get(vehicle.assignedDriverId) : undefined;
|
||||||
|
const assignedDriverName = assignedDriver
|
||||||
|
? `${assignedDriver.firstName ?? ""} ${assignedDriver.lastName ?? ""}`.trim()
|
||||||
|
: "";
|
||||||
|
return {
|
||||||
|
truckPlateNumber: vehicle?.powerPlateNo || vehicle?.plateNumber || null,
|
||||||
|
trailerPlateNumber: vehicle?.trailerPlateNo || null,
|
||||||
|
driverName: vehicle?.assignedDriverName || assignedDriverName || null,
|
||||||
|
driverLicense: assignedDriver?.licenseNumber || null,
|
||||||
|
driverPhone: assignedDriver?.phoneNumber || null,
|
||||||
|
truckType: vehicle?.vehicleType || truckType || null,
|
||||||
|
containerNumber: row?.containerNumber ?? null,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
const InfoRow = ({ label, value }: { label: string; value: string }) => (
|
const InfoRow = ({ label, value }: { label: string; value: string }) => (
|
||||||
<Stack gap={2}>
|
<Stack gap={2}>
|
||||||
<Text size="xs" c="dimmed" tt="uppercase" fw={600}>{label}</Text>
|
<Text size="xs" c="dimmed" tt="uppercase" fw={600}>{label}</Text>
|
||||||
@@ -325,6 +380,8 @@ const LastMilePage = () => {
|
|||||||
|
|
||||||
const [allocationOpen, setAllocationOpen] = useState(false);
|
const [allocationOpen, setAllocationOpen] = useState(false);
|
||||||
const [allocationContainers, setAllocationContainers] = useState<LastMileContainerRow[]>([]);
|
const [allocationContainers, setAllocationContainers] = useState<LastMileContainerRow[]>([]);
|
||||||
|
const [releaseItem, setReleaseItem] = useState<WarehouseInventoryItem | null>(null);
|
||||||
|
const [releaseTruckPrefill, setReleaseTruckPrefill] = useState<ReleaseOrderTruckPrefill | null>(null);
|
||||||
|
|
||||||
const { data: listData, isLoading } = useQuery({
|
const { data: listData, isLoading } = useQuery({
|
||||||
queryKey: QUERY_KEYS.LAST_MILE.list(),
|
queryKey: QUERY_KEYS.LAST_MILE.list(),
|
||||||
@@ -352,6 +409,27 @@ const LastMilePage = () => {
|
|||||||
|
|
||||||
const records = listData?.data ?? [];
|
const records = listData?.data ?? [];
|
||||||
|
|
||||||
|
const needsDriverLookup = records.some((record) => record.vehicle?.assignedDriverId);
|
||||||
|
|
||||||
|
const { data: driversData } = useQuery({
|
||||||
|
queryKey: ["drivers", "list", "ACTIVE"],
|
||||||
|
queryFn: async () => {
|
||||||
|
const res = await driversService.getAll({ status: "ACTIVE" });
|
||||||
|
return res.data;
|
||||||
|
},
|
||||||
|
enabled: needsDriverLookup,
|
||||||
|
});
|
||||||
|
|
||||||
|
const driversById = useMemo(
|
||||||
|
() => new Map((driversData ?? []).map((driver) => [driver.id, driver])),
|
||||||
|
[driversData],
|
||||||
|
);
|
||||||
|
|
||||||
|
const { data: pickupReadyRows = [] } = useQuery({
|
||||||
|
queryKey: ["warehouse-inventory", "import-pickup-ready-queue"],
|
||||||
|
queryFn: () => warehouseService.importPickupReadyQueue().then((r) => r.data),
|
||||||
|
});
|
||||||
|
|
||||||
const vehicleOptions = useMemo(
|
const vehicleOptions = useMemo(
|
||||||
() =>
|
() =>
|
||||||
(Array.isArray(vehiclesData) ? vehiclesData : []).map((v) => {
|
(Array.isArray(vehiclesData) ? vehiclesData : []).map((v) => {
|
||||||
@@ -533,6 +611,15 @@ const LastMilePage = () => {
|
|||||||
[records, activeId],
|
[records, activeId],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const pickupReadyByBooking = useMemo(() => {
|
||||||
|
const map = new Map<string, ImportUnloadedItem>();
|
||||||
|
for (const row of pickupReadyRows) {
|
||||||
|
if (row.bookingId) map.set(row.bookingId, row);
|
||||||
|
if (row.bookingReference) map.set(row.bookingReference, row);
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
}, [pickupReadyRows]);
|
||||||
|
|
||||||
const selectedIds = useMemo(
|
const selectedIds = useMemo(
|
||||||
() => Object.keys(rowSelection).filter((id) => rowSelection[id]),
|
() => Object.keys(rowSelection).filter((id) => rowSelection[id]),
|
||||||
[rowSelection],
|
[rowSelection],
|
||||||
@@ -569,6 +656,7 @@ const LastMilePage = () => {
|
|||||||
const term = search.trim().toLowerCase();
|
const term = search.trim().toLowerCase();
|
||||||
return records.filter((r) => {
|
return records.filter((r) => {
|
||||||
if (!matchesFilter(r)) return false;
|
if (!matchesFilter(r)) return false;
|
||||||
|
if (filterPostPaymentPending && !(r.remainingPayment > 0)) return false;
|
||||||
if (!term) return true;
|
if (!term) return true;
|
||||||
return [bookingRef(r), customerName(r), deliveryLocation(r), cargoDesc(r)]
|
return [bookingRef(r), customerName(r), deliveryLocation(r), cargoDesc(r)]
|
||||||
.join(" ")
|
.join(" ")
|
||||||
@@ -649,6 +737,37 @@ const LastMilePage = () => {
|
|||||||
setTripSlipOpen(true);
|
setTripSlipOpen(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const openTruckArrival = (record: LastMileRecord) => {
|
||||||
|
if (!isAssigned(record)) {
|
||||||
|
toast({
|
||||||
|
title: "Assign a truck first",
|
||||||
|
description: "Truck arrival opens after a last-mile vehicle is assigned.",
|
||||||
|
variant: "destructive",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const row = pickupReadyByBooking.get(record.bookingId) ?? pickupReadyByBooking.get(bookingRef(record));
|
||||||
|
if (!row) {
|
||||||
|
toast({
|
||||||
|
title: "Import inventory is not pickup-ready",
|
||||||
|
description: `${bookingRef(record)} must be unloaded and pass inspection before truck arrival.`,
|
||||||
|
variant: "destructive",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setReleaseTruckPrefill(releasePrefillFromLastMile(record, row, driversById));
|
||||||
|
setReleaseItem(toReleaseInventoryItem(row));
|
||||||
|
};
|
||||||
|
|
||||||
|
const closeTruckArrival = () => {
|
||||||
|
setReleaseItem(null);
|
||||||
|
setReleaseTruckPrefill(null);
|
||||||
|
void qc.invalidateQueries({ queryKey: ["warehouse-inventory"] });
|
||||||
|
void qc.invalidateQueries({ queryKey: QUERY_KEYS.LAST_MILE.ROOT });
|
||||||
|
};
|
||||||
|
|
||||||
const printTripSlip = () => {
|
const printTripSlip = () => {
|
||||||
if (!tripSlipRecord) return;
|
if (!tripSlipRecord) return;
|
||||||
const win = window.open("", "_blank", "width=820,height=920");
|
const win = window.open("", "_blank", "width=820,height=920");
|
||||||
@@ -809,6 +928,9 @@ const LastMilePage = () => {
|
|||||||
const assigned = isAssigned(row.original);
|
const assigned = isAssigned(row.original);
|
||||||
const nextStatus = NEXT_STATUS[row.original.status];
|
const nextStatus = NEXT_STATUS[row.original.status];
|
||||||
const canPrint = row.original.status !== "PAYMENT_PENDING";
|
const canPrint = row.original.status !== "PAYMENT_PENDING";
|
||||||
|
const releaseRow =
|
||||||
|
pickupReadyByBooking.get(row.original.bookingId) ?? pickupReadyByBooking.get(bookingRef(row.original));
|
||||||
|
const truckArrivalLabel = releaseRow?.releaseOrderReference ? "Truck Leaving" : "Truck Arrival";
|
||||||
return (
|
return (
|
||||||
<Group gap={4} justify="flex-end" wrap="nowrap">
|
<Group gap={4} justify="flex-end" wrap="nowrap">
|
||||||
<Menu position="bottom-end" width={200} withinPortal>
|
<Menu position="bottom-end" width={200} withinPortal>
|
||||||
@@ -840,6 +962,13 @@ const LastMilePage = () => {
|
|||||||
>
|
>
|
||||||
Reassign
|
Reassign
|
||||||
</Menu.Item>
|
</Menu.Item>
|
||||||
|
<Menu.Item
|
||||||
|
leftSection={<Truck size={15} />}
|
||||||
|
disabled={!assigned}
|
||||||
|
onClick={() => openTruckArrival(row.original)}
|
||||||
|
>
|
||||||
|
{truckArrivalLabel}
|
||||||
|
</Menu.Item>
|
||||||
<Menu.Divider />
|
<Menu.Divider />
|
||||||
<Menu.Item
|
<Menu.Item
|
||||||
leftSection={<Eye size={15} />}
|
leftSection={<Eye size={15} />}
|
||||||
@@ -869,7 +998,7 @@ const LastMilePage = () => {
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [vehicleOptions]);
|
}, [vehicleOptions, pickupReadyByBooking]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack gap="md">
|
<Stack gap="md">
|
||||||
@@ -1358,6 +1487,13 @@ const LastMilePage = () => {
|
|||||||
</Group>
|
</Group>
|
||||||
</Stack>
|
</Stack>
|
||||||
</Modal>
|
</Modal>
|
||||||
|
|
||||||
|
<ReleaseOrderModal
|
||||||
|
opened={Boolean(releaseItem)}
|
||||||
|
onClose={closeTruckArrival}
|
||||||
|
item={releaseItem}
|
||||||
|
truckPrefill={releaseTruckPrefill}
|
||||||
|
/>
|
||||||
</Stack>
|
</Stack>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ import {
|
|||||||
RingProgress,
|
RingProgress,
|
||||||
Stack,
|
Stack,
|
||||||
Text,
|
Text,
|
||||||
|
Textarea,
|
||||||
|
TextInput,
|
||||||
ThemeIcon,
|
ThemeIcon,
|
||||||
Title,
|
Title,
|
||||||
} from "@mantine/core";
|
} from "@mantine/core";
|
||||||
@@ -88,6 +90,10 @@ export default function TrainScheduleV2DetailPage() {
|
|||||||
const [previewResult, setPreviewResult] = useState<TrainSchedulePreviewResponse | null>(null);
|
const [previewResult, setPreviewResult] = useState<TrainSchedulePreviewResponse | null>(null);
|
||||||
const [containerPlacements, setContainerPlacements] = useState<ContainerPlacement[]>([]);
|
const [containerPlacements, setContainerPlacements] = useState<ContainerPlacement[]>([]);
|
||||||
const [maintenanceOpen, setMaintenanceOpen] = useState(false);
|
const [maintenanceOpen, setMaintenanceOpen] = useState(false);
|
||||||
|
const [gatepassSecuredAt, setGatepassSecuredAt] = useState("");
|
||||||
|
const [gatepassReference, setGatepassReference] = useState("");
|
||||||
|
const [gatepassFileUrl, setGatepassFileUrl] = useState("");
|
||||||
|
const [gatepassNotes, setGatepassNotes] = useState("");
|
||||||
const autoPreviewedRef = useRef(false);
|
const autoPreviewedRef = useRef(false);
|
||||||
|
|
||||||
const detailQuery = useQuery(
|
const detailQuery = useQuery(
|
||||||
@@ -98,6 +104,42 @@ export default function TrainScheduleV2DetailPage() {
|
|||||||
);
|
);
|
||||||
const schedule = detailQuery.data;
|
const schedule = detailQuery.data;
|
||||||
const freightType: FreightType | undefined = schedule?.freightType as FreightType | undefined;
|
const freightType: FreightType | undefined = schedule?.freightType as FreightType | undefined;
|
||||||
|
const isDjiboutiPort = (value?: string | null) =>
|
||||||
|
["DJIBOUTI", "DORALEH", "DMP", "DCT", "NAGAD"].some((token) =>
|
||||||
|
(value ?? "").toUpperCase().includes(token),
|
||||||
|
);
|
||||||
|
const gatepassApplies = Boolean(
|
||||||
|
schedule &&
|
||||||
|
((schedule.direction === "IMPORT" &&
|
||||||
|
isDjiboutiPort(`${schedule.originStation?.code ?? ""} ${schedule.originStation?.label ?? ""}`)) ||
|
||||||
|
(schedule.direction === "EXPORT" &&
|
||||||
|
isDjiboutiPort(`${schedule.destinationStation?.code ?? ""} ${schedule.destinationStation?.label ?? ""}`))),
|
||||||
|
);
|
||||||
|
const gatepassQuery = useQuery({
|
||||||
|
queryKey: ["train-scheduling", "gatepass", scheduleId],
|
||||||
|
queryFn: () => trainSchedulingService.getImportDjiboutiOperation(scheduleId as string),
|
||||||
|
enabled: Boolean(scheduleId && gatepassApplies),
|
||||||
|
});
|
||||||
|
const secureGatepass = useMutation({
|
||||||
|
mutationFn: () =>
|
||||||
|
trainSchedulingService.grantImportDjiboutiGatepass(scheduleId as string, {
|
||||||
|
securedAt: gatepassSecuredAt ? new Date(gatepassSecuredAt).toISOString() : undefined,
|
||||||
|
reference: gatepassReference.trim() || undefined,
|
||||||
|
fileUrl: gatepassFileUrl.trim() || undefined,
|
||||||
|
notes: gatepassNotes.trim() || undefined,
|
||||||
|
}),
|
||||||
|
onSuccess: () => {
|
||||||
|
toast({ title: "Gate pass secured" });
|
||||||
|
void gatepassQuery.refetch();
|
||||||
|
},
|
||||||
|
onError: (error) => {
|
||||||
|
toast({
|
||||||
|
title: "Gate pass failed",
|
||||||
|
description: parseError(error, "Could not secure gate pass"),
|
||||||
|
variant: "destructive",
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
const eligibleFilters = useMemo(
|
const eligibleFilters = useMemo(
|
||||||
() =>
|
() =>
|
||||||
@@ -133,6 +175,16 @@ export default function TrainScheduleV2DetailPage() {
|
|||||||
: trainSchedulingService.downloadImportDjiboutiLoadListDocument(id),
|
: trainSchedulingService.downloadImportDjiboutiLoadListDocument(id),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const operation = gatepassQuery.data;
|
||||||
|
if (!operation) return;
|
||||||
|
const secured = operation.gatepassSecuredAt ?? operation.gatepassGrantedAt;
|
||||||
|
setGatepassSecuredAt(secured ? new Date(secured).toISOString().slice(0, 16) : "");
|
||||||
|
setGatepassReference(operation.documents?.GATE_PASS?.reference ?? "");
|
||||||
|
setGatepassFileUrl(operation.documents?.GATE_PASS?.fileUrl ?? "");
|
||||||
|
setGatepassNotes(operation.documents?.GATE_PASS?.notes ?? operation.notes ?? "");
|
||||||
|
}, [gatepassQuery.data]);
|
||||||
|
|
||||||
const assignedIds = useMemo(
|
const assignedIds = useMemo(
|
||||||
() => (schedule?.bookings ?? []).map((b) => b.id),
|
() => (schedule?.bookings ?? []).map((b) => b.id),
|
||||||
[schedule?.bookings],
|
[schedule?.bookings],
|
||||||
@@ -899,6 +951,83 @@ export default function TrainScheduleV2DetailPage() {
|
|||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
{gatepassApplies ? (
|
||||||
|
<Paper radius="xl" p="lg" withBorder>
|
||||||
|
<Stack gap="md">
|
||||||
|
<Group justify="space-between" align="flex-start" wrap="wrap">
|
||||||
|
<Group gap="md" align="flex-start" wrap="nowrap">
|
||||||
|
<ThemeIcon
|
||||||
|
size={44}
|
||||||
|
radius="md"
|
||||||
|
variant="light"
|
||||||
|
color={gatepassQuery.data?.gatepassStatus === "SECURED" ? "edr-green" : "orange"}
|
||||||
|
>
|
||||||
|
<FileText size={22} />
|
||||||
|
</ThemeIcon>
|
||||||
|
<Stack gap={4}>
|
||||||
|
<Group gap="sm">
|
||||||
|
<Title order={4} fw={700}>
|
||||||
|
Djibouti Port gate pass
|
||||||
|
</Title>
|
||||||
|
<Badge
|
||||||
|
color={gatepassQuery.data?.gatepassStatus === "SECURED" ? "green" : "orange"}
|
||||||
|
variant="light"
|
||||||
|
>
|
||||||
|
{gatepassQuery.data?.gatepassStatus ?? "NOT_SECURED"}
|
||||||
|
</Badge>
|
||||||
|
</Group>
|
||||||
|
<Text size="sm" c="dimmed">
|
||||||
|
{schedule.direction === "IMPORT"
|
||||||
|
? "Secure before dispatch from Djibouti."
|
||||||
|
: "Secure after dispatch before Djibouti Port entry / unloading."}
|
||||||
|
</Text>
|
||||||
|
</Stack>
|
||||||
|
</Group>
|
||||||
|
{gatepassQuery.isLoading ? <Loader size="sm" /> : null}
|
||||||
|
</Group>
|
||||||
|
|
||||||
|
<Group align="flex-end" grow>
|
||||||
|
<TextInput
|
||||||
|
label="Secured date"
|
||||||
|
type="datetime-local"
|
||||||
|
value={gatepassSecuredAt}
|
||||||
|
onChange={(event) => setGatepassSecuredAt(event.currentTarget.value)}
|
||||||
|
/>
|
||||||
|
<TextInput
|
||||||
|
label="Document reference"
|
||||||
|
placeholder="Optional"
|
||||||
|
value={gatepassReference}
|
||||||
|
onChange={(event) => setGatepassReference(event.currentTarget.value)}
|
||||||
|
/>
|
||||||
|
<TextInput
|
||||||
|
label="Document URL"
|
||||||
|
placeholder="Optional upload/link"
|
||||||
|
value={gatepassFileUrl}
|
||||||
|
onChange={(event) => setGatepassFileUrl(event.currentTarget.value)}
|
||||||
|
/>
|
||||||
|
</Group>
|
||||||
|
<Textarea
|
||||||
|
label="Notes"
|
||||||
|
placeholder="Optional"
|
||||||
|
autosize
|
||||||
|
minRows={2}
|
||||||
|
value={gatepassNotes}
|
||||||
|
onChange={(event) => setGatepassNotes(event.currentTarget.value)}
|
||||||
|
/>
|
||||||
|
<Group justify="flex-end">
|
||||||
|
<Button
|
||||||
|
color="edr-green"
|
||||||
|
leftSection={<CheckCircle2 size={16} />}
|
||||||
|
loading={secureGatepass.isPending}
|
||||||
|
onClick={() => secureGatepass.mutate()}
|
||||||
|
>
|
||||||
|
Save as Secured
|
||||||
|
</Button>
|
||||||
|
</Group>
|
||||||
|
</Stack>
|
||||||
|
</Paper>
|
||||||
|
) : null}
|
||||||
|
|
||||||
<Paper radius="xl" p="lg">
|
<Paper radius="xl" p="lg">
|
||||||
<Stack gap="lg">
|
<Stack gap="lg">
|
||||||
{/* Workflow header with ring progress */}
|
{/* Workflow header with ring progress */}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Fragment, useState } from 'react';
|
import { Fragment, useEffect, useMemo, useState } from 'react';
|
||||||
import {
|
import {
|
||||||
Badge,
|
Badge,
|
||||||
Button,
|
Button,
|
||||||
@@ -6,6 +6,7 @@ import {
|
|||||||
Container,
|
Container,
|
||||||
Group,
|
Group,
|
||||||
Loader,
|
Loader,
|
||||||
|
Select,
|
||||||
Stack,
|
Stack,
|
||||||
Table,
|
Table,
|
||||||
Text,
|
Text,
|
||||||
@@ -21,11 +22,17 @@ import {
|
|||||||
} from '@/components/warehouses';
|
} from '@/components/warehouses';
|
||||||
import {
|
import {
|
||||||
useAutoUnloadArrivedBookings,
|
useAutoUnloadArrivedBookings,
|
||||||
|
useAllWarehouseYards,
|
||||||
|
useAllWarehouseZones,
|
||||||
useImportArriveQueue,
|
useImportArriveQueue,
|
||||||
useImportTrainItems,
|
useImportTrainItems,
|
||||||
|
useWarehouses,
|
||||||
} from '@/hooks/useWarehouses';
|
} from '@/hooks/useWarehouses';
|
||||||
import { useToast } from '@/hooks/use-toast';
|
import { useToast } from '@/hooks/use-toast';
|
||||||
import type { AutoUnloadArrivedResult, ImportTrain, ImportTrainItem } from '@/types/warehouse';
|
import type { AutoUnloadArrivedResult, ImportTrain, ImportTrainItem, Warehouse, WarehouseYard, WarehouseZone } from '@/types/warehouse';
|
||||||
|
|
||||||
|
type UnloadAssignment = { bookingId: string; warehouseId: string; yardId: string; zoneId: string };
|
||||||
|
type AssignmentDraft = Partial<Omit<UnloadAssignment, 'bookingId'>>;
|
||||||
|
|
||||||
const getErrorMessage = (error: unknown) => {
|
const getErrorMessage = (error: unknown) => {
|
||||||
if (error && typeof error === 'object' && 'response' in error) {
|
if (error && typeof error === 'object' && 'response' in error) {
|
||||||
@@ -43,8 +50,54 @@ const getPendingUnloadBookings = (train: ImportTrain) =>
|
|||||||
const isFullyUnloaded = (train: ImportTrain) =>
|
const isFullyUnloaded = (train: ImportTrain) =>
|
||||||
Boolean(train.fullyUnloaded) || (train.totalBookings > 0 && getPendingUnloadBookings(train) === 0);
|
Boolean(train.fullyUnloaded) || (train.totalBookings > 0 && getPendingUnloadBookings(train) === 0);
|
||||||
|
|
||||||
function ImportTrainDetailRows({ scheduleId }: { scheduleId: string }) {
|
const locationTypesForFreight = (freightType: string | null | undefined) => {
|
||||||
|
const normalized = (freightType ?? '').toUpperCase();
|
||||||
|
if (normalized === 'CONTAINER') {
|
||||||
|
return { yardTypes: ['CONTAINER_YARD', 'GENERAL_CARGO_YARD'], zoneTypes: ['CONTAINER_ZONE', 'GENERAL_CARGO_ZONE'] };
|
||||||
|
}
|
||||||
|
return { yardTypes: ['BULK_YARD', 'GENERAL_CARGO_YARD'], zoneTypes: ['BULK_ZONE', 'GENERAL_CARGO_ZONE'] };
|
||||||
|
};
|
||||||
|
|
||||||
|
const isContainerFreight = (freightType: string | null | undefined) =>
|
||||||
|
(freightType ?? '').toUpperCase() === 'CONTAINER';
|
||||||
|
|
||||||
|
function isUnloadPending(item: ImportTrainItem) {
|
||||||
|
return !item.currentStatus || item.currentStatus === 'RECEIVED';
|
||||||
|
}
|
||||||
|
|
||||||
|
function ImportTrainDetailRows({
|
||||||
|
scheduleId,
|
||||||
|
warehouses,
|
||||||
|
yards,
|
||||||
|
zones,
|
||||||
|
assignments,
|
||||||
|
onAssignmentChange,
|
||||||
|
onReadyChange,
|
||||||
|
}: {
|
||||||
|
scheduleId: string;
|
||||||
|
warehouses: Warehouse[];
|
||||||
|
yards: WarehouseYard[];
|
||||||
|
zones: WarehouseZone[];
|
||||||
|
assignments: Record<string, AssignmentDraft>;
|
||||||
|
onAssignmentChange: (bookingId: string, draft: AssignmentDraft) => void;
|
||||||
|
onReadyChange: (ready: boolean) => void;
|
||||||
|
}) {
|
||||||
const { data: items = [], isLoading } = useImportTrainItems(scheduleId);
|
const { data: items = [], isLoading } = useImportTrainItems(scheduleId);
|
||||||
|
const warehouseOptions = useMemo(
|
||||||
|
() => warehouses.map((warehouse) => ({ value: warehouse.id, label: `${warehouse.name} (${warehouse.code})` })),
|
||||||
|
[warehouses],
|
||||||
|
);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const pending = items.filter(isUnloadPending);
|
||||||
|
onReadyChange(
|
||||||
|
pending.length > 0 &&
|
||||||
|
pending.every((item) => {
|
||||||
|
const draft = assignments[item.bookingId];
|
||||||
|
return Boolean(draft?.warehouseId && draft.yardId && draft.zoneId);
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}, [assignments, items]);
|
||||||
|
|
||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
return (
|
return (
|
||||||
@@ -73,12 +126,26 @@ function ImportTrainDetailRows({ scheduleId }: { scheduleId: string }) {
|
|||||||
<Table.Th>Weight</Table.Th>
|
<Table.Th>Weight</Table.Th>
|
||||||
<Table.Th>Arrival</Table.Th>
|
<Table.Th>Arrival</Table.Th>
|
||||||
<Table.Th>Status</Table.Th>
|
<Table.Th>Status</Table.Th>
|
||||||
|
<Table.Th>Warehouse</Table.Th>
|
||||||
|
<Table.Th>Yard</Table.Th>
|
||||||
|
<Table.Th>Zone</Table.Th>
|
||||||
<Table.Th>Inspection</Table.Th>
|
<Table.Th>Inspection</Table.Th>
|
||||||
<Table.Th>Pickup</Table.Th>
|
<Table.Th>Pickup</Table.Th>
|
||||||
</Table.Tr>
|
</Table.Tr>
|
||||||
</Table.Thead>
|
</Table.Thead>
|
||||||
<Table.Tbody>
|
<Table.Tbody>
|
||||||
{items.map((item: ImportTrainItem) => (
|
{items.map((item: ImportTrainItem) => {
|
||||||
|
const draft = assignments[item.bookingId] ?? {};
|
||||||
|
const { yardTypes, zoneTypes } = locationTypesForFreight(item.freightType);
|
||||||
|
const yardOptions = yards
|
||||||
|
.filter((yard) => yard.warehouseId === draft.warehouseId && yardTypes.includes(yard.type))
|
||||||
|
.map((yard) => ({ value: yard.id, label: `${yard.name} (${yard.code})` }));
|
||||||
|
const zoneOptions = zones
|
||||||
|
.filter((zone) => zone.yardId === draft.yardId && zoneTypes.includes(zone.type))
|
||||||
|
.map((zone) => ({ value: zone.id, label: `${zone.name} (${zone.code})` }));
|
||||||
|
const pending = isUnloadPending(item);
|
||||||
|
|
||||||
|
return (
|
||||||
<Table.Tr key={item.bookingId}>
|
<Table.Tr key={item.bookingId}>
|
||||||
<Table.Td>
|
<Table.Td>
|
||||||
<Text size="sm" fw={600}>
|
<Text size="sm" fw={600}>
|
||||||
@@ -95,6 +162,41 @@ function ImportTrainDetailRows({ scheduleId }: { scheduleId: string }) {
|
|||||||
{item.currentStatus ?? 'PENDING'}
|
{item.currentStatus ?? 'PENDING'}
|
||||||
</Badge>
|
</Badge>
|
||||||
</Table.Td>
|
</Table.Td>
|
||||||
|
<Table.Td>
|
||||||
|
<Select
|
||||||
|
placeholder="Warehouse"
|
||||||
|
data={warehouseOptions}
|
||||||
|
value={draft.warehouseId ?? null}
|
||||||
|
onChange={(value) => onAssignmentChange(item.bookingId, { warehouseId: value ?? undefined })}
|
||||||
|
searchable
|
||||||
|
disabled={!pending}
|
||||||
|
w={210}
|
||||||
|
/>
|
||||||
|
</Table.Td>
|
||||||
|
<Table.Td>
|
||||||
|
<Select
|
||||||
|
placeholder={isContainerFreight(item.freightType) ? 'Container yard' : 'Bulk yard'}
|
||||||
|
data={yardOptions}
|
||||||
|
value={draft.yardId ?? null}
|
||||||
|
onChange={(value) =>
|
||||||
|
onAssignmentChange(item.bookingId, { ...draft, yardId: value ?? undefined, zoneId: undefined })
|
||||||
|
}
|
||||||
|
searchable
|
||||||
|
disabled={!pending || !draft.warehouseId}
|
||||||
|
w={190}
|
||||||
|
/>
|
||||||
|
</Table.Td>
|
||||||
|
<Table.Td>
|
||||||
|
<Select
|
||||||
|
placeholder={isContainerFreight(item.freightType) ? 'Container zone' : 'Bulk zone'}
|
||||||
|
data={zoneOptions}
|
||||||
|
value={draft.zoneId ?? null}
|
||||||
|
onChange={(value) => onAssignmentChange(item.bookingId, { ...draft, zoneId: value ?? undefined })}
|
||||||
|
searchable
|
||||||
|
disabled={!pending || !draft.yardId}
|
||||||
|
w={190}
|
||||||
|
/>
|
||||||
|
</Table.Td>
|
||||||
<Table.Td>
|
<Table.Td>
|
||||||
<Badge variant="light" color={item.inspectionStatus === 'PASSED' ? 'green' : 'gray'} size="sm">
|
<Badge variant="light" color={item.inspectionStatus === 'PASSED' ? 'green' : 'gray'} size="sm">
|
||||||
{item.inspectionStatus ?? 'Not inspected'}
|
{item.inspectionStatus ?? 'Not inspected'}
|
||||||
@@ -102,7 +204,8 @@ function ImportTrainDetailRows({ scheduleId }: { scheduleId: string }) {
|
|||||||
</Table.Td>
|
</Table.Td>
|
||||||
<Table.Td>{item.pickupOption.replace(/_/g, ' ')}</Table.Td>
|
<Table.Td>{item.pickupOption.replace(/_/g, ' ')}</Table.Td>
|
||||||
</Table.Tr>
|
</Table.Tr>
|
||||||
))}
|
);
|
||||||
|
})}
|
||||||
</Table.Tbody>
|
</Table.Tbody>
|
||||||
</Table>
|
</Table>
|
||||||
);
|
);
|
||||||
@@ -112,11 +215,36 @@ function ImportTrainDetailRows({ scheduleId }: { scheduleId: string }) {
|
|||||||
export default function ArrivalQueuePage() {
|
export default function ArrivalQueuePage() {
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
const { data: trains = [], isLoading } = useImportArriveQueue();
|
const { data: trains = [], isLoading } = useImportArriveQueue();
|
||||||
|
const { data: warehouses = [], isLoading: warehousesLoading } = useWarehouses({ status: 'ACTIVE' });
|
||||||
|
const { data: yards = [] } = useAllWarehouseYards();
|
||||||
|
const { data: zones = [] } = useAllWarehouseZones();
|
||||||
const autoUnload = useAutoUnloadArrivedBookings();
|
const autoUnload = useAutoUnloadArrivedBookings();
|
||||||
const [openScheduleId, setOpenScheduleId] = useState<string | null>(null);
|
const [openScheduleId, setOpenScheduleId] = useState<string | null>(null);
|
||||||
const [busyScheduleId, setBusyScheduleId] = useState<string | null>(null);
|
const [busyScheduleId, setBusyScheduleId] = useState<string | null>(null);
|
||||||
|
const [assignmentsBySchedule, setAssignmentsBySchedule] = useState<Record<string, Record<string, AssignmentDraft>>>({});
|
||||||
|
const [readyBySchedule, setReadyBySchedule] = useState<Record<string, boolean>>({});
|
||||||
|
|
||||||
const unloadTrain = async (train: ImportTrain) => {
|
const unloadTrain = async (train: ImportTrain) => {
|
||||||
|
const assignments = Object.entries(assignmentsBySchedule[train.scheduleId] ?? {})
|
||||||
|
.filter((entry): entry is [string, Required<AssignmentDraft>] =>
|
||||||
|
Boolean(entry[1].warehouseId && entry[1].yardId && entry[1].zoneId),
|
||||||
|
)
|
||||||
|
.map(([bookingId, draft]) => ({
|
||||||
|
bookingId,
|
||||||
|
warehouseId: draft.warehouseId,
|
||||||
|
yardId: draft.yardId,
|
||||||
|
zoneId: draft.zoneId,
|
||||||
|
}));
|
||||||
|
|
||||||
|
if (!readyBySchedule[train.scheduleId] || assignments.length === 0) {
|
||||||
|
toast({
|
||||||
|
variant: 'destructive',
|
||||||
|
title: 'Assign locations',
|
||||||
|
description: 'Select warehouse, yard and zone for each pending booking before unloading.',
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (isFullyUnloaded(train)) {
|
if (isFullyUnloaded(train)) {
|
||||||
toast({
|
toast({
|
||||||
title: 'Already unloaded',
|
title: 'Already unloaded',
|
||||||
@@ -127,7 +255,9 @@ export default function ArrivalQueuePage() {
|
|||||||
|
|
||||||
setBusyScheduleId(train.scheduleId);
|
setBusyScheduleId(train.scheduleId);
|
||||||
try {
|
try {
|
||||||
const res = (await autoUnload.mutateAsync(train.scheduleId)) as { data: AutoUnloadArrivedResult };
|
const res = (await autoUnload.mutateAsync({ scheduleId: train.scheduleId, assignments })) as {
|
||||||
|
data: AutoUnloadArrivedResult;
|
||||||
|
};
|
||||||
const result = res.data;
|
const result = res.data;
|
||||||
const alreadyUnloaded = result.unloadedCount === 0 && result.skippedCount > 0 && result.failedCount === 0;
|
const alreadyUnloaded = result.unloadedCount === 0 && result.skippedCount > 0 && result.failedCount === 0;
|
||||||
const firstReason = result.results.find((item) => item.reason)?.reason;
|
const firstReason = result.results.find((item) => item.reason)?.reason;
|
||||||
@@ -169,10 +299,12 @@ export default function ArrivalQueuePage() {
|
|||||||
|
|
||||||
<Card withBorder radius="md" padding="lg">
|
<Card withBorder radius="md" padding="lg">
|
||||||
<Group justify="space-between" mb="md">
|
<Group justify="space-between" mb="md">
|
||||||
<Text fw={600}>{trains.length} arrived import train(s)</Text>
|
<Stack gap={2}>
|
||||||
<Text size="sm" c="dimmed">
|
<Text fw={600}>{trains.length} arrived import train(s)</Text>
|
||||||
Open a train to review assigned bookings, then auto unload it.
|
<Text size="sm" c="dimmed">
|
||||||
</Text>
|
Open a train, assign each booking to a warehouse yard and zone, then unload it.
|
||||||
|
</Text>
|
||||||
|
</Stack>
|
||||||
</Group>
|
</Group>
|
||||||
|
|
||||||
{isLoading ? (
|
{isLoading ? (
|
||||||
@@ -254,7 +386,7 @@ export default function ArrivalQueuePage() {
|
|||||||
color={fullyUnloaded ? 'gray' : 'orange'}
|
color={fullyUnloaded ? 'gray' : 'orange'}
|
||||||
leftSection={busyScheduleId === train.scheduleId ? <PackageOpen size={14} /> : <Truck size={14} />}
|
leftSection={busyScheduleId === train.scheduleId ? <PackageOpen size={14} /> : <Truck size={14} />}
|
||||||
loading={busyScheduleId === train.scheduleId}
|
loading={busyScheduleId === train.scheduleId}
|
||||||
disabled={fullyUnloaded || train.totalBookings === 0}
|
disabled={fullyUnloaded || train.totalBookings === 0 || !readyBySchedule[train.scheduleId] || warehousesLoading}
|
||||||
onClick={() => unloadTrain(train)}
|
onClick={() => unloadTrain(train)}
|
||||||
>
|
>
|
||||||
{fullyUnloaded ? 'Already Unloaded' : 'Auto Unload'}
|
{fullyUnloaded ? 'Already Unloaded' : 'Auto Unload'}
|
||||||
@@ -265,7 +397,27 @@ export default function ArrivalQueuePage() {
|
|||||||
{isOpen && (
|
{isOpen && (
|
||||||
<Table.Tr>
|
<Table.Tr>
|
||||||
<Table.Td colSpan={10} bg="var(--mantine-color-gray-0)">
|
<Table.Td colSpan={10} bg="var(--mantine-color-gray-0)">
|
||||||
<ImportTrainDetailRows scheduleId={train.scheduleId} />
|
<ImportTrainDetailRows
|
||||||
|
scheduleId={train.scheduleId}
|
||||||
|
warehouses={warehouses}
|
||||||
|
yards={yards}
|
||||||
|
zones={zones}
|
||||||
|
assignments={assignmentsBySchedule[train.scheduleId] ?? {}}
|
||||||
|
onAssignmentChange={(bookingId, draft) =>
|
||||||
|
setAssignmentsBySchedule((current) => ({
|
||||||
|
...current,
|
||||||
|
[train.scheduleId]: {
|
||||||
|
...(current[train.scheduleId] ?? {}),
|
||||||
|
[bookingId]: draft.warehouseId
|
||||||
|
? draft
|
||||||
|
: {},
|
||||||
|
},
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
onReadyChange={(ready) =>
|
||||||
|
setReadyBySchedule((current) => ({ ...current, [train.scheduleId]: ready }))
|
||||||
|
}
|
||||||
|
/>
|
||||||
</Table.Td>
|
</Table.Td>
|
||||||
</Table.Tr>
|
</Table.Tr>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { useMemo, useState } from 'react';
|
import { useEffect, useMemo, useState } from 'react';
|
||||||
import {
|
import {
|
||||||
ActionIcon,
|
ActionIcon,
|
||||||
Badge,
|
Badge,
|
||||||
@@ -29,6 +29,7 @@ import { useToast } from '@/hooks/use-toast';
|
|||||||
import {
|
import {
|
||||||
WAREHOUSE_INVOICE_STATUSES,
|
WAREHOUSE_INVOICE_STATUSES,
|
||||||
type WarehouseFeeInvoice,
|
type WarehouseFeeInvoice,
|
||||||
|
type WarehouseGatewayPaymentMethod,
|
||||||
type WarehouseInvoiceStatus,
|
type WarehouseInvoiceStatus,
|
||||||
} from '@/types/warehouse';
|
} from '@/types/warehouse';
|
||||||
import { openPdfBlob } from '@/components/warehouses/pdf';
|
import { openPdfBlob } from '@/components/warehouses/pdf';
|
||||||
@@ -164,15 +165,23 @@ function InvoiceDetailModal({ id, onClose }: { id: string | null; onClose: () =>
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
const pay = useMutation(api.warehouses.payInvoice.mutationOptions());
|
const pay = useMutation(api.warehouses.payInvoice.mutationOptions());
|
||||||
|
const payOnline = useMutation(api.warehouses.payInvoiceOnline.mutationOptions());
|
||||||
const cancel = useMutation(api.warehouses.cancelInvoice.mutationOptions());
|
const cancel = useMutation(api.warehouses.cancelInvoice.mutationOptions());
|
||||||
const gateClear = useMutation(api.warehouses.gateClearance.mutationOptions());
|
const gateClear = useMutation(api.warehouses.gateClearance.mutationOptions());
|
||||||
const [payAmount, setPayAmount] = useState<number | ''>('');
|
const [payAmount, setPayAmount] = useState<number | ''>('');
|
||||||
const [driverName, setDriverName] = useState('');
|
const [driverName, setDriverName] = useState('');
|
||||||
const [driverPhone, setDriverPhone] = useState('');
|
const [driverPhone, setDriverPhone] = useState('');
|
||||||
|
const [gatewayMethod, setGatewayMethod] = useState<WarehouseGatewayPaymentMethod>('TELEBIRR');
|
||||||
|
const [payerAccount, setPayerAccount] = useState('');
|
||||||
|
|
||||||
const canPay = inv && (inv.status === 'ISSUED' || inv.status === 'PARTIALLY_PAID');
|
const canPay = inv && (inv.status === 'ISSUED' || inv.status === 'PARTIALLY_PAID');
|
||||||
const canGateClear = inv?.status === 'PAID' && Boolean(inv.inventoryId);
|
const canGateClear = inv?.status === 'PAID' && Boolean(inv.inventoryId);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setGatewayMethod(inv?.currency === 'USD' ? 'WAAFI' : 'TELEBIRR');
|
||||||
|
setPayerAccount('');
|
||||||
|
}, [inv?.id, inv?.currency]);
|
||||||
|
|
||||||
const downloadInvoicePdf = async (invoice: WarehouseFeeInvoice) => {
|
const downloadInvoicePdf = async (invoice: WarehouseFeeInvoice) => {
|
||||||
const pdfWindow = window.open('', '_blank');
|
const pdfWindow = window.open('', '_blank');
|
||||||
try {
|
try {
|
||||||
@@ -302,6 +311,34 @@ function InvoiceDetailModal({ id, onClose }: { id: string | null; onClose: () =>
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleOnlinePay = async () => {
|
||||||
|
if (!inv) return;
|
||||||
|
try {
|
||||||
|
const currentUrl = window.location.href;
|
||||||
|
const result = await payOnline.mutateAsync({
|
||||||
|
id: inv.id,
|
||||||
|
payload: {
|
||||||
|
method: gatewayMethod,
|
||||||
|
platform: 'web',
|
||||||
|
payerAccount: payerAccount.trim() || undefined,
|
||||||
|
returnUrl: currentUrl,
|
||||||
|
failureUrl: currentUrl,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const url = result.clientAction?.url;
|
||||||
|
if (url) {
|
||||||
|
window.location.href = url;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
toast({
|
||||||
|
title: 'Payment initiated',
|
||||||
|
description: 'No redirect URL was returned by the payment provider.',
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
toast({ variant: 'destructive', title: 'Payment failed', description: extractErrorMessage(e) });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const handleCancel = async () => {
|
const handleCancel = async () => {
|
||||||
if (!inv) return;
|
if (!inv) return;
|
||||||
try {
|
try {
|
||||||
@@ -359,7 +396,31 @@ function InvoiceDetailModal({ id, onClose }: { id: string | null; onClose: () =>
|
|||||||
|
|
||||||
{canPay && (
|
{canPay && (
|
||||||
<>
|
<>
|
||||||
<Divider label="Record payment" labelPosition="left" />
|
<Divider label="Online payment" labelPosition="left" />
|
||||||
|
<Group align="flex-end">
|
||||||
|
<Select
|
||||||
|
label="Provider"
|
||||||
|
value={gatewayMethod}
|
||||||
|
onChange={(v) => setGatewayMethod((v as WarehouseGatewayPaymentMethod) ?? 'TELEBIRR')}
|
||||||
|
data={[
|
||||||
|
{ value: 'TELEBIRR', label: 'Telebirr' },
|
||||||
|
{ value: 'WAAFI', label: 'Waafi' },
|
||||||
|
]}
|
||||||
|
style={{ flex: 1 }}
|
||||||
|
/>
|
||||||
|
<TextInput
|
||||||
|
label="Wallet phone / account"
|
||||||
|
value={payerAccount}
|
||||||
|
onChange={(e) => setPayerAccount(e.currentTarget.value)}
|
||||||
|
placeholder="Optional"
|
||||||
|
style={{ flex: 1 }}
|
||||||
|
/>
|
||||||
|
<Button leftSection={<CreditCard size={16} />} loading={payOnline.isPending} onClick={handleOnlinePay}>
|
||||||
|
Pay with {gatewayMethod === 'WAAFI' ? 'Waafi' : 'Telebirr'}
|
||||||
|
</Button>
|
||||||
|
</Group>
|
||||||
|
|
||||||
|
<Divider label="Record manual payment" labelPosition="left" />
|
||||||
<Group align="flex-end">
|
<Group align="flex-end">
|
||||||
<NumberInput
|
<NumberInput
|
||||||
label="Amount"
|
label="Amount"
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ import {
|
|||||||
} from '@mantine/core';
|
} from '@mantine/core';
|
||||||
import { Info, Plus, Trash2 } from 'lucide-react';
|
import { Info, Plus, Trash2 } from 'lucide-react';
|
||||||
|
|
||||||
|
import { useQuery } from '@tanstack/react-query';
|
||||||
|
|
||||||
import { PageContainer, PageHeader } from '@/components/page';
|
import { PageContainer, PageHeader } from '@/components/page';
|
||||||
import { useToast } from '@/hooks/use-toast';
|
import { useToast } from '@/hooks/use-toast';
|
||||||
import {
|
import {
|
||||||
@@ -29,7 +31,9 @@ import {
|
|||||||
useDeleteFeeRule,
|
useDeleteFeeRule,
|
||||||
useFeeRules,
|
useFeeRules,
|
||||||
} from '@/hooks/useWarehouses';
|
} from '@/hooks/useWarehouses';
|
||||||
|
import { api } from '@/services/api';
|
||||||
import { FEE_RULE_TYPES, type FeeRuleType } from '@/types/warehouse';
|
import { FEE_RULE_TYPES, type FeeRuleType } from '@/types/warehouse';
|
||||||
|
import { extractErrorMessage } from '@/components/warehouses/options';
|
||||||
|
|
||||||
const FREIGHT = [
|
const FREIGHT = [
|
||||||
{ value: 'CONTAINER', label: 'Container' },
|
{ value: 'CONTAINER', label: 'Container' },
|
||||||
@@ -38,6 +42,7 @@ const FREIGHT = [
|
|||||||
const TRADE = [
|
const TRADE = [
|
||||||
{ value: 'IMPORT', label: 'Import' },
|
{ value: 'IMPORT', label: 'Import' },
|
||||||
{ value: 'EXPORT', label: 'Export' },
|
{ value: 'EXPORT', label: 'Export' },
|
||||||
|
{ value: 'BOTH', label: 'Import & Export' },
|
||||||
{ value: 'DOMESTIC', label: 'Domestic' },
|
{ value: 'DOMESTIC', label: 'Domestic' },
|
||||||
];
|
];
|
||||||
const CURRENCIES = [
|
const CURRENCIES = [
|
||||||
@@ -53,6 +58,23 @@ const numberValue = (value: string | number, fallback = 0) => {
|
|||||||
};
|
};
|
||||||
const anyLabel = (value: string, label: string) => value.trim() || `Any ${label}`;
|
const anyLabel = (value: string, label: string) => value.trim() || `Any ${label}`;
|
||||||
const dash = '-';
|
const dash = '-';
|
||||||
|
type CodeOptionSource = {
|
||||||
|
id?: string;
|
||||||
|
code?: string;
|
||||||
|
cargoTypeName?: string;
|
||||||
|
label?: string;
|
||||||
|
name?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
const codeOptions = (rows: unknown[]) =>
|
||||||
|
(rows as CodeOptionSource[])
|
||||||
|
.filter((row) => row.code)
|
||||||
|
.map((row) => ({
|
||||||
|
value: row.code as string,
|
||||||
|
label: `${row.cargoTypeName ?? row.label ?? row.name ?? row.code} (${row.code})`,
|
||||||
|
}));
|
||||||
|
|
||||||
|
const isUnknownTiersError = (error: unknown) => extractErrorMessage(error).includes('property tiers should not exist');
|
||||||
|
|
||||||
export default function WarehouseRulesPage() {
|
export default function WarehouseRulesPage() {
|
||||||
return (
|
return (
|
||||||
@@ -319,6 +341,12 @@ function AllocationRules() {
|
|||||||
function FeeRules() {
|
function FeeRules() {
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
const { data, isLoading } = useFeeRules();
|
const { data, isLoading } = useFeeRules();
|
||||||
|
const { data: cargoTypes = [], isLoading: cargoTypesLoading } = useQuery(
|
||||||
|
api.cargoTypes.list.queryOptions({ staleTime: Infinity }),
|
||||||
|
);
|
||||||
|
const { data: containerTypes = [], isLoading: containerTypesLoading } = useQuery(
|
||||||
|
api.containerTypes.list.queryOptions({ staleTime: Infinity }),
|
||||||
|
);
|
||||||
const create = useCreateFeeRule();
|
const create = useCreateFeeRule();
|
||||||
const remove = useDeleteFeeRule();
|
const remove = useDeleteFeeRule();
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
@@ -328,11 +356,56 @@ function FeeRules() {
|
|||||||
freightType: '',
|
freightType: '',
|
||||||
tradeDirection: '',
|
tradeDirection: '',
|
||||||
cargoTypeCode: '',
|
cargoTypeCode: '',
|
||||||
|
containerType: '',
|
||||||
freeDays: 3,
|
freeDays: 3,
|
||||||
ratePerDay: 0,
|
ratePerDay: 0,
|
||||||
|
tiers: [] as Array<{ fromDay: number; toDay: number | null; ratePerDay: number }>,
|
||||||
currency: 'USD',
|
currency: 'USD',
|
||||||
});
|
});
|
||||||
const rules = data ?? [];
|
const rules = data ?? [];
|
||||||
|
const cargoTypeOptions = codeOptions(cargoTypes);
|
||||||
|
const containerTypeOptions = codeOptions(containerTypes);
|
||||||
|
const isBulkRule = form.freightType === 'BULK';
|
||||||
|
const isContainerRule = form.freightType === 'CONTAINER';
|
||||||
|
|
||||||
|
const resetForm = () =>
|
||||||
|
setForm({
|
||||||
|
name: '',
|
||||||
|
ruleType: 'DEMURRAGE_FEE',
|
||||||
|
freightType: '',
|
||||||
|
tradeDirection: '',
|
||||||
|
cargoTypeCode: '',
|
||||||
|
containerType: '',
|
||||||
|
freeDays: 3,
|
||||||
|
ratePerDay: 0,
|
||||||
|
tiers: [],
|
||||||
|
currency: 'USD',
|
||||||
|
});
|
||||||
|
|
||||||
|
const addTier = () =>
|
||||||
|
setForm((f) => {
|
||||||
|
const last = f.tiers[f.tiers.length - 1];
|
||||||
|
const fromDay = last?.toDay ? last.toDay + 1 : f.tiers.length ? last.fromDay + 1 : f.freeDays + 1;
|
||||||
|
return {
|
||||||
|
...f,
|
||||||
|
tiers: [...f.tiers, { fromDay, toDay: fromDay, ratePerDay: f.ratePerDay || 0 }],
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
const updateTier = (
|
||||||
|
index: number,
|
||||||
|
patch: Partial<{ fromDay: number; toDay: number | null; ratePerDay: number }>,
|
||||||
|
) =>
|
||||||
|
setForm((f) => ({
|
||||||
|
...f,
|
||||||
|
tiers: f.tiers.map((tier, i) => (i === index ? { ...tier, ...patch } : tier)),
|
||||||
|
}));
|
||||||
|
|
||||||
|
const removeTier = (index: number) =>
|
||||||
|
setForm((f) => ({
|
||||||
|
...f,
|
||||||
|
tiers: f.tiers.filter((_, i) => i !== index),
|
||||||
|
}));
|
||||||
|
|
||||||
const submit = async () => {
|
const submit = async () => {
|
||||||
if (!form.name.trim()) {
|
if (!form.name.trim()) {
|
||||||
@@ -340,18 +413,68 @@ function FeeRules() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await create.mutateAsync({
|
const tiers = form.tiers.map((tier) => ({
|
||||||
|
fromDay: tier.fromDay,
|
||||||
|
toDay: tier.toDay || null,
|
||||||
|
ratePerDay: tier.ratePerDay,
|
||||||
|
}));
|
||||||
|
for (const [index, tier] of tiers.entries()) {
|
||||||
|
if (!Number.isInteger(tier.fromDay) || tier.fromDay < 1) {
|
||||||
|
toast({ variant: 'destructive', title: `Tier ${index + 1}: from day must be at least 1` });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (tier.toDay != null && tier.toDay < tier.fromDay) {
|
||||||
|
toast({ variant: 'destructive', title: `Tier ${index + 1}: to day must be after from day` });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (tier.ratePerDay < 0) {
|
||||||
|
toast({ variant: 'destructive', title: `Tier ${index + 1}: amount must be zero or greater` });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const payload = {
|
||||||
name: form.name.trim(),
|
name: form.name.trim(),
|
||||||
ruleType: form.ruleType,
|
ruleType: form.ruleType,
|
||||||
freightType: clean(form.freightType) ?? null,
|
freightType: clean(form.freightType) ?? null,
|
||||||
tradeDirection: clean(form.tradeDirection) ?? null,
|
tradeDirection: clean(form.tradeDirection) ?? null,
|
||||||
cargoTypeCode: clean(form.cargoTypeCode) ?? null,
|
cargoTypeCode: isBulkRule ? (clean(form.cargoTypeCode) ?? null) : null,
|
||||||
|
containerType: isContainerRule ? (clean(form.containerType) ?? null) : null,
|
||||||
freeDays: form.freeDays,
|
freeDays: form.freeDays,
|
||||||
ratePerDay: form.ratePerDay,
|
ratePerDay: form.ratePerDay,
|
||||||
currency: form.currency || 'USD',
|
currency: form.currency || 'USD',
|
||||||
} as never);
|
...(tiers.length ? { tiers } : {}),
|
||||||
toast({ title: 'Fee rule created' });
|
};
|
||||||
setOpen(false);
|
|
||||||
|
try {
|
||||||
|
await create.mutateAsync(payload as never);
|
||||||
|
toast({ title: 'Fee rule created' });
|
||||||
|
setOpen(false);
|
||||||
|
resetForm();
|
||||||
|
} catch (error) {
|
||||||
|
if (tiers.length && isUnknownTiersError(error)) {
|
||||||
|
const legacyPayload: Omit<typeof payload, 'tiers'> = {
|
||||||
|
name: payload.name,
|
||||||
|
ruleType: payload.ruleType,
|
||||||
|
freightType: payload.freightType,
|
||||||
|
tradeDirection: payload.tradeDirection,
|
||||||
|
cargoTypeCode: payload.cargoTypeCode,
|
||||||
|
containerType: payload.containerType,
|
||||||
|
freeDays: payload.freeDays,
|
||||||
|
ratePerDay: payload.ratePerDay,
|
||||||
|
currency: payload.currency,
|
||||||
|
};
|
||||||
|
await create.mutateAsync(legacyPayload as never);
|
||||||
|
toast({
|
||||||
|
title: 'Fee rule created without tiers',
|
||||||
|
description: 'The connected API does not support progressive tiers yet. Deploy the warehouse fee tier migration/API to save tier rows.',
|
||||||
|
});
|
||||||
|
setOpen(false);
|
||||||
|
resetForm();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
toast({ variant: 'destructive', title: 'Create failed', description: extractErrorMessage(error) });
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -370,7 +493,7 @@ function FeeRules() {
|
|||||||
<Loader />
|
<Loader />
|
||||||
</Group>
|
</Group>
|
||||||
) : (
|
) : (
|
||||||
<Table.ScrollContainer minWidth={900}>
|
<Table.ScrollContainer minWidth={1100}>
|
||||||
<Table striped highlightOnHover verticalSpacing="sm">
|
<Table striped highlightOnHover verticalSpacing="sm">
|
||||||
<Table.Thead>
|
<Table.Thead>
|
||||||
<Table.Tr>
|
<Table.Tr>
|
||||||
@@ -378,6 +501,9 @@ function FeeRules() {
|
|||||||
<Table.Th>Name</Table.Th>
|
<Table.Th>Name</Table.Th>
|
||||||
<Table.Th>Freight</Table.Th>
|
<Table.Th>Freight</Table.Th>
|
||||||
<Table.Th>Trade</Table.Th>
|
<Table.Th>Trade</Table.Th>
|
||||||
|
<Table.Th>Cargo</Table.Th>
|
||||||
|
<Table.Th>Container</Table.Th>
|
||||||
|
<Table.Th>Location scope</Table.Th>
|
||||||
<Table.Th>Free days</Table.Th>
|
<Table.Th>Free days</Table.Th>
|
||||||
<Table.Th>Rate / day</Table.Th>
|
<Table.Th>Rate / day</Table.Th>
|
||||||
<Table.Th>Active</Table.Th>
|
<Table.Th>Active</Table.Th>
|
||||||
@@ -395,6 +521,20 @@ function FeeRules() {
|
|||||||
<Table.Td>{rule.name}</Table.Td>
|
<Table.Td>{rule.name}</Table.Td>
|
||||||
<Table.Td>{rule.freightType ?? dash}</Table.Td>
|
<Table.Td>{rule.freightType ?? dash}</Table.Td>
|
||||||
<Table.Td>{rule.tradeDirection ?? dash}</Table.Td>
|
<Table.Td>{rule.tradeDirection ?? dash}</Table.Td>
|
||||||
|
<Table.Td>{rule.cargoTypeCode ?? dash}</Table.Td>
|
||||||
|
<Table.Td>{rule.containerType ?? dash}</Table.Td>
|
||||||
|
<Table.Td>
|
||||||
|
{[rule.facilityId, rule.warehouseId, rule.yardId, rule.zoneId].some(Boolean) ? (
|
||||||
|
<Stack gap={2}>
|
||||||
|
{rule.facilityId && <Text size="xs">Facility: {rule.facilityId}</Text>}
|
||||||
|
{rule.warehouseId && <Text size="xs">Warehouse: {rule.warehouseId}</Text>}
|
||||||
|
{rule.yardId && <Text size="xs">Yard: {rule.yardId}</Text>}
|
||||||
|
{rule.zoneId && <Text size="xs">Zone: {rule.zoneId}</Text>}
|
||||||
|
</Stack>
|
||||||
|
) : (
|
||||||
|
dash
|
||||||
|
)}
|
||||||
|
</Table.Td>
|
||||||
<Table.Td>{rule.freeDays}</Table.Td>
|
<Table.Td>{rule.freeDays}</Table.Td>
|
||||||
<Table.Td>
|
<Table.Td>
|
||||||
{Number(rule.ratePerDay).toLocaleString()} {rule.currency}
|
{Number(rule.ratePerDay).toLocaleString()} {rule.currency}
|
||||||
@@ -454,7 +594,14 @@ function FeeRules() {
|
|||||||
label="Freight type"
|
label="Freight type"
|
||||||
data={FREIGHT}
|
data={FREIGHT}
|
||||||
value={form.freightType || null}
|
value={form.freightType || null}
|
||||||
onChange={(value) => setForm((f) => ({ ...f, freightType: selectValue(value) }))}
|
onChange={(value) =>
|
||||||
|
setForm((f) => ({
|
||||||
|
...f,
|
||||||
|
freightType: selectValue(value),
|
||||||
|
cargoTypeCode: value === 'BULK' ? f.cargoTypeCode : '',
|
||||||
|
containerType: value === 'CONTAINER' ? f.containerType : '',
|
||||||
|
}))
|
||||||
|
}
|
||||||
clearable
|
clearable
|
||||||
/>
|
/>
|
||||||
<Select
|
<Select
|
||||||
@@ -464,15 +611,31 @@ function FeeRules() {
|
|||||||
onChange={(value) => setForm((f) => ({ ...f, tradeDirection: selectValue(value) }))}
|
onChange={(value) => setForm((f) => ({ ...f, tradeDirection: selectValue(value) }))}
|
||||||
clearable
|
clearable
|
||||||
/>
|
/>
|
||||||
<TextInput
|
{isBulkRule && (
|
||||||
label="Cargo type code"
|
<Select
|
||||||
value={form.cargoTypeCode}
|
label="Cargo type"
|
||||||
onChange={(e) => {
|
placeholder={cargoTypesLoading ? 'Loading cargo types...' : 'Any cargo'}
|
||||||
const value = e.currentTarget.value;
|
data={cargoTypeOptions}
|
||||||
setForm((f) => ({ ...f, cargoTypeCode: value }));
|
value={form.cargoTypeCode || null}
|
||||||
}}
|
onChange={(value) => setForm((f) => ({ ...f, cargoTypeCode: selectValue(value) }))}
|
||||||
/>
|
searchable
|
||||||
|
clearable
|
||||||
|
disabled={cargoTypesLoading}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</Group>
|
</Group>
|
||||||
|
{isContainerRule && (
|
||||||
|
<Select
|
||||||
|
label="Container type"
|
||||||
|
placeholder={containerTypesLoading ? 'Loading container types...' : 'Any container'}
|
||||||
|
data={containerTypeOptions}
|
||||||
|
value={form.containerType || null}
|
||||||
|
onChange={(value) => setForm((f) => ({ ...f, containerType: selectValue(value) }))}
|
||||||
|
searchable
|
||||||
|
clearable
|
||||||
|
disabled={containerTypesLoading}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
<Group grow>
|
<Group grow>
|
||||||
<NumberInput
|
<NumberInput
|
||||||
label="Free days"
|
label="Free days"
|
||||||
@@ -494,6 +657,51 @@ function FeeRules() {
|
|||||||
allowDeselect={false}
|
allowDeselect={false}
|
||||||
/>
|
/>
|
||||||
</Group>
|
</Group>
|
||||||
|
<Stack gap="xs">
|
||||||
|
<Group justify="space-between">
|
||||||
|
<Text size="sm" fw={600}>
|
||||||
|
Progressive tariff tiers
|
||||||
|
</Text>
|
||||||
|
<Button variant="light" size="xs" leftSection={<Plus size={14} />} onClick={addTier}>
|
||||||
|
Add tier
|
||||||
|
</Button>
|
||||||
|
</Group>
|
||||||
|
{form.tiers.map((tier, index) => (
|
||||||
|
<Group key={index} grow align="end">
|
||||||
|
<NumberInput
|
||||||
|
label="From day"
|
||||||
|
min={1}
|
||||||
|
value={tier.fromDay}
|
||||||
|
onChange={(value) => updateTier(index, { fromDay: numberValue(value, 1) || 1 })}
|
||||||
|
/>
|
||||||
|
<NumberInput
|
||||||
|
label="To day"
|
||||||
|
min={tier.fromDay}
|
||||||
|
value={tier.toDay ?? ''}
|
||||||
|
placeholder="Open"
|
||||||
|
onChange={(value) =>
|
||||||
|
updateTier(index, {
|
||||||
|
toDay: value === '' ? null : numberValue(value, tier.fromDay),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<NumberInput
|
||||||
|
label="Amount / day"
|
||||||
|
min={0}
|
||||||
|
value={tier.ratePerDay}
|
||||||
|
onChange={(value) => updateTier(index, { ratePerDay: numberValue(value) })}
|
||||||
|
/>
|
||||||
|
<ActionIcon variant="subtle" color="red" onClick={() => removeTier(index)} title="Remove tier">
|
||||||
|
<Trash2 size={16} />
|
||||||
|
</ActionIcon>
|
||||||
|
</Group>
|
||||||
|
))}
|
||||||
|
{form.tiers.length === 0 && (
|
||||||
|
<Text size="xs" c="dimmed">
|
||||||
|
No stepped tiers. The flat rate per day is used after the free days.
|
||||||
|
</Text>
|
||||||
|
)}
|
||||||
|
</Stack>
|
||||||
<Group justify="flex-end" mt="sm">
|
<Group justify="flex-end" mt="sm">
|
||||||
<Button variant="default" onClick={() => setOpen(false)}>
|
<Button variant="default" onClick={() => setOpen(false)}>
|
||||||
Cancel
|
Cancel
|
||||||
|
|||||||
@@ -84,6 +84,7 @@ import type {
|
|||||||
InventoryInquiryFilter,
|
InventoryInquiryFilter,
|
||||||
InventoryInquiryResult,
|
InventoryInquiryResult,
|
||||||
InventoryMovement,
|
InventoryMovement,
|
||||||
|
InitiateWarehouseInvoicePaymentPayload,
|
||||||
LoadableWagon,
|
LoadableWagon,
|
||||||
LoadInventoryPayload,
|
LoadInventoryPayload,
|
||||||
LoadPassedExportResult,
|
LoadPassedExportResult,
|
||||||
@@ -102,6 +103,7 @@ import type {
|
|||||||
WarehouseActivityLog,
|
WarehouseActivityLog,
|
||||||
WarehouseDashboard,
|
WarehouseDashboard,
|
||||||
WarehouseFeeInvoice,
|
WarehouseFeeInvoice,
|
||||||
|
WarehouseInvoicePaymentResponse,
|
||||||
WarehouseFilter,
|
WarehouseFilter,
|
||||||
WarehouseInventoryItem,
|
WarehouseInventoryItem,
|
||||||
WarehouseInvoiceFilter,
|
WarehouseInvoiceFilter,
|
||||||
@@ -943,12 +945,19 @@ export const api = {
|
|||||||
() => INVENTORY_INVALIDATIONS,
|
() => INVENTORY_INVALIDATIONS,
|
||||||
),
|
),
|
||||||
|
|
||||||
autoUnloadArrivedBookings: endpoint<string, AutoUnloadArrivedResult>(
|
autoUnloadArrivedBookings: endpoint<
|
||||||
|
{
|
||||||
|
scheduleId: string;
|
||||||
|
warehouseId?: string;
|
||||||
|
assignments?: { bookingId: string; warehouseId: string; yardId: string; zoneId: string }[];
|
||||||
|
},
|
||||||
|
AutoUnloadArrivedResult
|
||||||
|
>(
|
||||||
"warehouse-inventory",
|
"warehouse-inventory",
|
||||||
"auto-unload-arrived-bookings",
|
"auto-unload-arrived-bookings",
|
||||||
(scheduleId) =>
|
({ scheduleId, warehouseId, assignments }) =>
|
||||||
warehouseService
|
warehouseService
|
||||||
.autoUnloadArrivedBookings(scheduleId)
|
.autoUnloadArrivedBookings({ scheduleId, warehouseId, assignments })
|
||||||
.then((r) => r.data),
|
.then((r) => r.data),
|
||||||
undefined,
|
undefined,
|
||||||
() => INVENTORY_INVALIDATIONS,
|
() => INVENTORY_INVALIDATIONS,
|
||||||
@@ -1111,6 +1120,18 @@ export const api = {
|
|||||||
() => [["warehouse-fee-invoices"], ["warehouse-inventory"]],
|
() => [["warehouse-fee-invoices"], ["warehouse-inventory"]],
|
||||||
),
|
),
|
||||||
|
|
||||||
|
payInvoiceOnline: endpoint<
|
||||||
|
{ id: string; payload: InitiateWarehouseInvoicePaymentPayload },
|
||||||
|
WarehouseInvoicePaymentResponse
|
||||||
|
>(
|
||||||
|
"warehouse-fee-invoices",
|
||||||
|
"pay-online",
|
||||||
|
({ id, payload }) =>
|
||||||
|
warehouseService.payInvoiceOnline(id, payload).then((r) => r.data),
|
||||||
|
undefined,
|
||||||
|
() => [["warehouse-fee-invoices"], ["warehouse-inventory"]],
|
||||||
|
),
|
||||||
|
|
||||||
gateClearance: endpoint<string, WarehouseInventoryItem>(
|
gateClearance: endpoint<string, WarehouseInventoryItem>(
|
||||||
"warehouse-fee-invoices",
|
"warehouse-fee-invoices",
|
||||||
"gate-clearance",
|
"gate-clearance",
|
||||||
|
|||||||
@@ -29,9 +29,12 @@ export interface LastMileVehicle {
|
|||||||
plateNumber: string;
|
plateNumber: string;
|
||||||
manufacturer: string;
|
manufacturer: string;
|
||||||
model: string;
|
model: string;
|
||||||
|
vehicleType?: string | null;
|
||||||
code?: string | null;
|
code?: string | null;
|
||||||
powerPlateNo?: string | null;
|
powerPlateNo?: string | null;
|
||||||
trailerPlateNo?: string | null;
|
trailerPlateNo?: string | null;
|
||||||
|
assignedDriverId?: string | null;
|
||||||
|
assignedDriverName?: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface LastMileRecord {
|
export interface LastMileRecord {
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ export interface Vehicle {
|
|||||||
capacity: number;
|
capacity: number;
|
||||||
status: VehicleStatus;
|
status: VehicleStatus;
|
||||||
description?: string | null;
|
description?: string | null;
|
||||||
|
assignedDriverId?: string | null;
|
||||||
|
assignedDriverName?: string | null;
|
||||||
code?: string | null;
|
code?: string | null;
|
||||||
powerPlateNo?: string | null;
|
powerPlateNo?: string | null;
|
||||||
trailerPlateNo?: string | null;
|
trailerPlateNo?: string | null;
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ import type {
|
|||||||
WarehouseFeeInvoice,
|
WarehouseFeeInvoice,
|
||||||
WarehouseInvoiceFilter,
|
WarehouseInvoiceFilter,
|
||||||
PayInvoicePayload,
|
PayInvoicePayload,
|
||||||
|
InitiateWarehouseInvoicePaymentPayload,
|
||||||
|
WarehouseInvoicePaymentResponse,
|
||||||
BookingScheduleView,
|
BookingScheduleView,
|
||||||
InventoryFilter,
|
InventoryFilter,
|
||||||
InventoryInquiryFilter,
|
InventoryInquiryFilter,
|
||||||
@@ -171,10 +173,14 @@ export const warehouseService = {
|
|||||||
apiClient.get<ImportTrain[]>(URL_CONSTANTS.WAREHOUSE_INVENTORY.IMPORT_ARRIVE_QUEUE),
|
apiClient.get<ImportTrain[]>(URL_CONSTANTS.WAREHOUSE_INVENTORY.IMPORT_ARRIVE_QUEUE),
|
||||||
importTrainItems: (scheduleId: string) =>
|
importTrainItems: (scheduleId: string) =>
|
||||||
apiClient.get<ImportTrainItem[]>(URL_CONSTANTS.WAREHOUSE_INVENTORY.IMPORT_TRAIN_ITEMS(scheduleId)),
|
apiClient.get<ImportTrainItem[]>(URL_CONSTANTS.WAREHOUSE_INVENTORY.IMPORT_TRAIN_ITEMS(scheduleId)),
|
||||||
autoUnloadArrivedBookings: (scheduleId: string) =>
|
autoUnloadArrivedBookings: (payload: {
|
||||||
|
scheduleId: string;
|
||||||
|
warehouseId?: string;
|
||||||
|
assignments?: { bookingId: string; warehouseId: string; yardId: string; zoneId: string }[];
|
||||||
|
}) =>
|
||||||
apiClient.post<AutoUnloadArrivedResult>(
|
apiClient.post<AutoUnloadArrivedResult>(
|
||||||
URL_CONSTANTS.WAREHOUSE_INVENTORY.IMPORT_AUTO_UNLOAD_ARRIVED,
|
URL_CONSTANTS.WAREHOUSE_INVENTORY.IMPORT_AUTO_UNLOAD_ARRIVED,
|
||||||
{ scheduleId },
|
payload,
|
||||||
),
|
),
|
||||||
importUnloadedQueue: () =>
|
importUnloadedQueue: () =>
|
||||||
apiClient.get<ImportUnloadedItem[]>(URL_CONSTANTS.WAREHOUSE_INVENTORY.IMPORT_UNLOADED_QUEUE),
|
apiClient.get<ImportUnloadedItem[]>(URL_CONSTANTS.WAREHOUSE_INVENTORY.IMPORT_UNLOADED_QUEUE),
|
||||||
@@ -294,6 +300,8 @@ export const warehouseService = {
|
|||||||
apiClient.patch<WarehouseFeeInvoice>(URL_CONSTANTS.WAREHOUSE_INVOICES.CANCEL(id)),
|
apiClient.patch<WarehouseFeeInvoice>(URL_CONSTANTS.WAREHOUSE_INVOICES.CANCEL(id)),
|
||||||
payInvoice: (id: string, payload: PayInvoicePayload) =>
|
payInvoice: (id: string, payload: PayInvoicePayload) =>
|
||||||
apiClient.post<WarehouseFeeInvoice>(URL_CONSTANTS.WAREHOUSE_INVOICES.PAY(id), payload),
|
apiClient.post<WarehouseFeeInvoice>(URL_CONSTANTS.WAREHOUSE_INVOICES.PAY(id), payload),
|
||||||
|
payInvoiceOnline: (id: string, payload: InitiateWarehouseInvoicePaymentPayload) =>
|
||||||
|
apiClient.post<WarehouseInvoicePaymentResponse>(URL_CONSTANTS.WAREHOUSE_INVOICES.PAY_ONLINE(id), payload),
|
||||||
gateClearance: (inventoryId: string) =>
|
gateClearance: (inventoryId: string) =>
|
||||||
apiClient.post<WarehouseInventoryItem>(URL_CONSTANTS.WAREHOUSE_INVOICES.GATE_CLEARANCE(inventoryId), {}),
|
apiClient.post<WarehouseInventoryItem>(URL_CONSTANTS.WAREHOUSE_INVOICES.GATE_CLEARANCE(inventoryId), {}),
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -400,6 +400,7 @@ export interface TrainScheduleDetail {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type ImportDjiboutiDocumentType =
|
export type ImportDjiboutiDocumentType =
|
||||||
|
| "GATE_PASS"
|
||||||
| "DELIVERY_ORDER"
|
| "DELIVERY_ORDER"
|
||||||
| "PORT_INVOICE"
|
| "PORT_INVOICE"
|
||||||
| "DJIBOUTI_T1"
|
| "DJIBOUTI_T1"
|
||||||
@@ -422,6 +423,7 @@ export interface ImportDjiboutiOperation {
|
|||||||
status: {
|
status: {
|
||||||
documentsComplete: boolean;
|
documentsComplete: boolean;
|
||||||
missingDocuments: ImportDjiboutiDocumentType[];
|
missingDocuments: ImportDjiboutiDocumentType[];
|
||||||
|
gatepassStatus: "SECURED" | "NOT_SECURED";
|
||||||
gatepassGranted: boolean;
|
gatepassGranted: boolean;
|
||||||
readyForLoading: boolean;
|
readyForLoading: boolean;
|
||||||
loadedOnTrain: boolean;
|
loadedOnTrain: boolean;
|
||||||
@@ -430,6 +432,8 @@ export interface ImportDjiboutiOperation {
|
|||||||
};
|
};
|
||||||
documents: Partial<Record<ImportDjiboutiDocumentType, ImportDjiboutiDocumentRecord>>;
|
documents: Partial<Record<ImportDjiboutiDocumentType, ImportDjiboutiDocumentRecord>>;
|
||||||
gatepassGrantedAt: string | null;
|
gatepassGrantedAt: string | null;
|
||||||
|
gatepassSecuredAt?: string | null;
|
||||||
|
gatepassStatus: "SECURED" | "NOT_SECURED";
|
||||||
readyForLoadingAt: string | null;
|
readyForLoadingAt: string | null;
|
||||||
loadedOnTrainAt: string | null;
|
loadedOnTrainAt: string | null;
|
||||||
departedFromDjiboutiAt: string | null;
|
departedFromDjiboutiAt: string | null;
|
||||||
@@ -448,6 +452,10 @@ export interface UploadImportDjiboutiDocumentPayload {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface ImportDjiboutiActionPayload {
|
export interface ImportDjiboutiActionPayload {
|
||||||
|
securedAt?: string;
|
||||||
|
fileId?: string;
|
||||||
|
fileUrl?: string;
|
||||||
|
reference?: string;
|
||||||
notes?: string;
|
notes?: string;
|
||||||
performedBy?: string;
|
performedBy?: string;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -223,6 +223,11 @@ export interface InventoryBookingRef {
|
|||||||
tradeDirection?: string | null;
|
tradeDirection?: string | null;
|
||||||
// Present when the customer requested last-mile (door) delivery — gates the Last Mile action.
|
// Present when the customer requested last-mile (door) delivery — gates the Last Mile action.
|
||||||
lastMileDeliveryAddress?: string | null;
|
lastMileDeliveryAddress?: string | null;
|
||||||
|
customerTruckPlateNumber?: string | null;
|
||||||
|
customerTruckDriverName?: string | null;
|
||||||
|
customerTruckType?: string | null;
|
||||||
|
customerTruckContainerNumber?: string | null;
|
||||||
|
customerTruckAssignedAt?: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface InventoryMovement {
|
export interface InventoryMovement {
|
||||||
@@ -398,6 +403,11 @@ export interface EligibleBooking {
|
|||||||
firstMileDriverPhone: string | null;
|
firstMileDriverPhone: string | null;
|
||||||
firstMileDriverLicenseNumber: string | null;
|
firstMileDriverLicenseNumber: string | null;
|
||||||
firstMileTruckType: string | null;
|
firstMileTruckType: string | null;
|
||||||
|
customerTruckPlateNumber: string | null;
|
||||||
|
customerTruckDriverName: string | null;
|
||||||
|
customerTruckType: string | null;
|
||||||
|
customerTruckContainerNumber: string | null;
|
||||||
|
customerTruckAssignedAt: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface BulkReceivePayload {
|
export interface BulkReceivePayload {
|
||||||
@@ -433,6 +443,7 @@ export interface TruckEntrancePayload {
|
|||||||
packagingType?: string;
|
packagingType?: string;
|
||||||
unitCount?: number;
|
unitCount?: number;
|
||||||
grossWeightKg?: number;
|
grossWeightKg?: number;
|
||||||
|
weighingRequired?: boolean;
|
||||||
netWeightKg?: number;
|
netWeightKg?: number;
|
||||||
volumeDimensions?: string;
|
volumeDimensions?: string;
|
||||||
conditionAtReceipt?: string;
|
conditionAtReceipt?: string;
|
||||||
@@ -442,7 +453,7 @@ export interface TruckEntrancePayload {
|
|||||||
driverPhone: string;
|
driverPhone: string;
|
||||||
driverLicenseNumber?: string;
|
driverLicenseNumber?: string;
|
||||||
truckType?: string;
|
truckType?: string;
|
||||||
entranceTareWeightKg: number;
|
entranceTareWeightKg?: number;
|
||||||
exitTareWeightKg?: number;
|
exitTareWeightKg?: number;
|
||||||
driverSignatoryName?: string;
|
driverSignatoryName?: string;
|
||||||
warehouseManagerName?: string;
|
warehouseManagerName?: string;
|
||||||
@@ -573,6 +584,11 @@ export interface ImportUnloadedItem {
|
|||||||
inspectionStatus: string | null;
|
inspectionStatus: string | null;
|
||||||
pickupOption: string;
|
pickupOption: string;
|
||||||
lastMileRequested: boolean;
|
lastMileRequested: boolean;
|
||||||
|
customerTruckPlateNumber: string | null;
|
||||||
|
customerTruckDriverName: string | null;
|
||||||
|
customerTruckType: string | null;
|
||||||
|
customerTruckContainerNumber: string | null;
|
||||||
|
customerTruckAssignedAt: string | null;
|
||||||
currentStatus: string;
|
currentStatus: string;
|
||||||
releaseDate: string | null;
|
releaseDate: string | null;
|
||||||
releaseOrderReference: string | null;
|
releaseOrderReference: string | null;
|
||||||
@@ -589,6 +605,7 @@ export interface ImportTrainItem {
|
|||||||
wagonNumber: string | null;
|
wagonNumber: string | null;
|
||||||
sequenceNo: number | null;
|
sequenceNo: number | null;
|
||||||
allocatedWeightTons: number | null;
|
allocatedWeightTons: number | null;
|
||||||
|
freightType: string | null;
|
||||||
containerNumber: string | null;
|
containerNumber: string | null;
|
||||||
cargoType: string | null;
|
cargoType: string | null;
|
||||||
weight: number | null;
|
weight: number | null;
|
||||||
@@ -738,11 +755,25 @@ export interface FeeRule {
|
|||||||
zoneId?: string | null;
|
zoneId?: string | null;
|
||||||
freeDays: number;
|
freeDays: number;
|
||||||
ratePerDay: number;
|
ratePerDay: number;
|
||||||
|
tiers?: FeeRuleTier[];
|
||||||
currency: string;
|
currency: string;
|
||||||
isActive: boolean;
|
isActive: boolean;
|
||||||
}
|
}
|
||||||
export type SaveFeeRulePayload = Omit<FeeRule, 'id'>;
|
export type SaveFeeRulePayload = Omit<FeeRule, 'id'>;
|
||||||
|
|
||||||
|
export interface FeeRuleTier {
|
||||||
|
fromDay: number;
|
||||||
|
toDay: number | null;
|
||||||
|
ratePerDay: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface FeePreviewTier extends FeeRuleTier {
|
||||||
|
appliedFromDay: number;
|
||||||
|
appliedToDay: number;
|
||||||
|
days: number;
|
||||||
|
amount: number;
|
||||||
|
}
|
||||||
|
|
||||||
export interface FeePreview {
|
export interface FeePreview {
|
||||||
ruleType: FeeRuleType;
|
ruleType: FeeRuleType;
|
||||||
ruleId: string | null;
|
ruleId: string | null;
|
||||||
@@ -760,6 +791,7 @@ export interface FeePreview {
|
|||||||
containerCount: number;
|
containerCount: number;
|
||||||
billableUnits: number;
|
billableUnits: number;
|
||||||
amount: number;
|
amount: number;
|
||||||
|
tiers?: FeePreviewTier[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AllocationPreviewResult {
|
export interface AllocationPreviewResult {
|
||||||
@@ -868,6 +900,27 @@ export interface PayInvoicePayload {
|
|||||||
driverPhone?: string;
|
driverPhone?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type WarehouseGatewayPaymentMethod = 'TELEBIRR' | 'WAAFI';
|
||||||
|
|
||||||
|
export interface InitiateWarehouseInvoicePaymentPayload {
|
||||||
|
method: WarehouseGatewayPaymentMethod;
|
||||||
|
platform?: 'web' | 'mobile';
|
||||||
|
payerAccount?: string;
|
||||||
|
returnUrl?: string;
|
||||||
|
failureUrl?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface WarehouseInvoicePaymentResponse {
|
||||||
|
intentId: string;
|
||||||
|
status?: string;
|
||||||
|
merchantOrderId?: string;
|
||||||
|
clientAction?: {
|
||||||
|
type?: string;
|
||||||
|
url?: string;
|
||||||
|
[key: string]: unknown;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
// ── Payloads ───────────────────────────────────────────────────────────────
|
// ── Payloads ───────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
export interface SaveWarehousePayload {
|
export interface SaveWarehousePayload {
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { useEffect, useState } from "react";
|
||||||
import { useNavigate, useParams } from "react-router-dom";
|
import { useNavigate, useParams } from "react-router-dom";
|
||||||
import { useMutation, useQuery } from "@tanstack/react-query";
|
import { useMutation, useQuery } from "@tanstack/react-query";
|
||||||
import {
|
import {
|
||||||
@@ -9,6 +10,7 @@ import {
|
|||||||
Group,
|
Group,
|
||||||
Loader,
|
Loader,
|
||||||
Paper,
|
Paper,
|
||||||
|
Select,
|
||||||
SimpleGrid,
|
SimpleGrid,
|
||||||
Stack,
|
Stack,
|
||||||
Table,
|
Table,
|
||||||
@@ -65,6 +67,7 @@ function MetaItem({ label, value }: { label: string; value: string }) {
|
|||||||
export default function InvoiceDetailPage() {
|
export default function InvoiceDetailPage() {
|
||||||
const { id = "" } = useParams();
|
const { id = "" } = useParams();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
const [paymentMethod, setPaymentMethod] = useState<"TELEBIRR" | "WAAFI">("TELEBIRR");
|
||||||
|
|
||||||
const {
|
const {
|
||||||
data: invoice,
|
data: invoice,
|
||||||
@@ -89,6 +92,11 @@ export default function InvoiceDetailPage() {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!invoice) return;
|
||||||
|
setPaymentMethod(invoice.currency === "USD" ? "WAAFI" : "TELEBIRR");
|
||||||
|
}, [invoice?.currency]);
|
||||||
|
|
||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
return (
|
return (
|
||||||
<Center py={80}>
|
<Center py={80}>
|
||||||
@@ -119,8 +127,14 @@ export default function InvoiceDetailPage() {
|
|||||||
|
|
||||||
const payable = isPayable(invoice.status);
|
const payable = isPayable(invoice.status);
|
||||||
const lines = invoice.lines ?? [];
|
const lines = invoice.lines ?? [];
|
||||||
|
const amountDue = Number(invoice.balanceAmount ?? invoice.totalAmount);
|
||||||
|
|
||||||
const handlePay = () => {
|
const handlePay = () => {
|
||||||
|
<<<<<<< HEAD
|
||||||
|
const returnUrl = `${window.location.origin}/payment/success`;
|
||||||
|
const failureUrl = `${window.location.origin}/payment/failure`;
|
||||||
|
payMutation.mutate({ id, payload: { method: paymentMethod, returnUrl, failureUrl } });
|
||||||
|
=======
|
||||||
setPayModalOpen(true);
|
setPayModalOpen(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -170,6 +184,7 @@ export default function InvoiceDetailPage() {
|
|||||||
}
|
}
|
||||||
toast.error("This invoice's source isn't linked to a booking.");
|
toast.error("This invoice's source isn't linked to a booking.");
|
||||||
}
|
}
|
||||||
|
>>>>>>> 03740ee719f22f9617379a652b26f13b6870f671
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -199,6 +214,20 @@ export default function InvoiceDetailPage() {
|
|||||||
</Title>
|
</Title>
|
||||||
<InvoiceStatusBadge status={invoice.status} />
|
<InvoiceStatusBadge status={invoice.status} />
|
||||||
</Group>
|
</Group>
|
||||||
|
<<<<<<< HEAD
|
||||||
|
{payable && (
|
||||||
|
<Group align="flex-end" gap="sm">
|
||||||
|
<Select
|
||||||
|
label="Payment provider"
|
||||||
|
value={paymentMethod}
|
||||||
|
onChange={(value) => setPaymentMethod((value as "TELEBIRR" | "WAAFI") ?? "TELEBIRR")}
|
||||||
|
data={[
|
||||||
|
{ value: "TELEBIRR", label: "Telebirr" },
|
||||||
|
{ value: "WAAFI", label: "Waafi" },
|
||||||
|
]}
|
||||||
|
w={170}
|
||||||
|
/>
|
||||||
|
=======
|
||||||
<Group gap={8} wrap="wrap">
|
<Group gap={8} wrap="wrap">
|
||||||
{canViewSource && (
|
{canViewSource && (
|
||||||
<Button
|
<Button
|
||||||
@@ -242,6 +271,7 @@ export default function InvoiceDetailPage() {
|
|||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
{payable && (
|
{payable && (
|
||||||
|
>>>>>>> 03740ee719f22f9617379a652b26f13b6870f671
|
||||||
<Button
|
<Button
|
||||||
color="edr-green"
|
color="edr-green"
|
||||||
radius="md"
|
radius="md"
|
||||||
@@ -249,6 +279,14 @@ export default function InvoiceDetailPage() {
|
|||||||
leftSection={<CreditCard size={16} />}
|
leftSection={<CreditCard size={16} />}
|
||||||
loading={payMutation.isPending}
|
loading={payMutation.isPending}
|
||||||
onClick={handlePay}
|
onClick={handlePay}
|
||||||
|
<<<<<<< HEAD
|
||||||
|
styles={{ root: { fontWeight: 600, height: 42, paddingInline: 18 } }}
|
||||||
|
>
|
||||||
|
Pay {formatCurrency(amountDue, invoice.currency)}
|
||||||
|
</Button>
|
||||||
|
</Group>
|
||||||
|
)}
|
||||||
|
=======
|
||||||
styles={{
|
styles={{
|
||||||
root: { fontWeight: 600, height: 42, paddingInline: 18 },
|
root: { fontWeight: 600, height: 42, paddingInline: 18 },
|
||||||
}}
|
}}
|
||||||
@@ -258,6 +296,7 @@ export default function InvoiceDetailPage() {
|
|||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
</Group>
|
</Group>
|
||||||
|
>>>>>>> 03740ee719f22f9617379a652b26f13b6870f671
|
||||||
</Group>
|
</Group>
|
||||||
|
|
||||||
{/* Summary */}
|
{/* Summary */}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import { ActivityCard } from "./components/ActivityCard";
|
|||||||
import { ClearanceCard } from "./components/ClearanceCard";
|
import { ClearanceCard } from "./components/ClearanceCard";
|
||||||
import { ContainersCard } from "./components/ContainersCard";
|
import { ContainersCard } from "./components/ContainersCard";
|
||||||
import { ContractCard } from "./components/ContractCard";
|
import { ContractCard } from "./components/ContractCard";
|
||||||
|
import { CustomerTruckAssignmentCard } from "./components/CustomerTruckAssignmentCard";
|
||||||
import { DocRow, IconSquare } from "./components/Documents";
|
import { DocRow, IconSquare } from "./components/Documents";
|
||||||
import { KeyFactsStrip } from "./components/KeyFactsStrip";
|
import { KeyFactsStrip } from "./components/KeyFactsStrip";
|
||||||
import { BodyGrid, CardTitle, PageShell, SectionCard } from "./components/layout";
|
import { BodyGrid, CardTitle, PageShell, SectionCard } from "./components/layout";
|
||||||
@@ -38,7 +39,13 @@ import { SupportCard } from "./components/SupportCard";
|
|||||||
import { fmtDate, isNegative, priceTotal } from "./utils";
|
import { fmtDate, isNegative, priceTotal } from "./utils";
|
||||||
import { useScrollToHash } from "@/hooks/useScrollToHash";
|
import { useScrollToHash } from "@/hooks/useScrollToHash";
|
||||||
|
|
||||||
export function ReadonlyBookingView({ booking }: { booking: Freight.IBooking }) {
|
export function ReadonlyBookingView({
|
||||||
|
booking,
|
||||||
|
onBookingUpdated,
|
||||||
|
}: {
|
||||||
|
booking: Freight.IBooking;
|
||||||
|
onBookingUpdated?: () => void;
|
||||||
|
}) {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
// Deep-link support: e.g. /bookings/:id#warehouse-payments from an invoice.
|
// Deep-link support: e.g. /bookings/:id#warehouse-payments from an invoice.
|
||||||
useScrollToHash();
|
useScrollToHash();
|
||||||
@@ -102,7 +109,19 @@ export function ReadonlyBookingView({ booking }: { booking: Freight.IBooking })
|
|||||||
(isGeneralContract
|
(isGeneralContract
|
||||||
? status === "FULLY_EXECUTED"
|
? status === "FULLY_EXECUTED"
|
||||||
: status === "SELECTED_FOR_BATCH");
|
: status === "SELECTED_FOR_BATCH");
|
||||||
const canApproveDelivery = status === "COMPLETED";
|
const canApproveDelivery =
|
||||||
|
status === "COMPLETED" ||
|
||||||
|
(status === "TRUCK_ASSIGNED" && Boolean(booking.customerTruckArrivedAt));
|
||||||
|
const usesCustomerTruck =
|
||||||
|
booking.tradeDirection === "IMPORT"
|
||||||
|
? !booking.lastMileDeliveryAddress
|
||||||
|
: booking.tradeDirection === "EXPORT"
|
||||||
|
? !booking.firstMilePickupAddress
|
||||||
|
: !booking.firstMilePickupAddress && !booking.lastMileDeliveryAddress;
|
||||||
|
const canAssignCustomerTruck =
|
||||||
|
booking.paymentStatus === "PAID" &&
|
||||||
|
usesCustomerTruck &&
|
||||||
|
["PAID", "IN_TRANSIT", "COMPLETED", "TRUCK_ASSIGNED"].includes(status);
|
||||||
const showCountdown = canPay && !!booking.paymentDeadline;
|
const showCountdown = canPay && !!booking.paymentDeadline;
|
||||||
const isExpired = status === "EXPIRED";
|
const isExpired = status === "EXPIRED";
|
||||||
const isPendingConsolidation = status === "PENDING_CONSOLIDATION";
|
const isPendingConsolidation = status === "PENDING_CONSOLIDATION";
|
||||||
@@ -193,6 +212,12 @@ export function ReadonlyBookingView({ booking }: { booking: Freight.IBooking })
|
|||||||
|
|
||||||
<ShipmentTrackingCard bookingId={booking.id} />
|
<ShipmentTrackingCard bookingId={booking.id} />
|
||||||
|
|
||||||
|
{canAssignCustomerTruck && (
|
||||||
|
<CustomerTruckAssignmentCard
|
||||||
|
booking={booking}
|
||||||
|
onAssigned={onBookingUpdated ?? (() => {})}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
<WarehousePaymentsSection bookingId={booking.id} />
|
<WarehousePaymentsSection bookingId={booking.id} />
|
||||||
|
|
||||||
{booking.files && booking.files.length > 0 && (
|
{booking.files && booking.files.length > 0 && (
|
||||||
|
|||||||
@@ -0,0 +1,151 @@
|
|||||||
|
import { Alert, Button, Group, Select, SimpleGrid, Stack, Text, TextInput } from "@mantine/core";
|
||||||
|
import { useMutation } from "@tanstack/react-query";
|
||||||
|
import type { Freight } from "@edr/types";
|
||||||
|
import { Download, Lock, Truck } from "lucide-react";
|
||||||
|
import { useState } from "react";
|
||||||
|
|
||||||
|
import { api } from "@/services/api";
|
||||||
|
|
||||||
|
import { CardTitle, SectionCard } from "./layout";
|
||||||
|
|
||||||
|
const TRUCK_TYPES = ["Flatbed", "Container Chassis", "Lowboy", "Box Truck", "Tipper"];
|
||||||
|
const ISO_CONTAINER_PATTERN = /^[A-Z]{4}\d{7}$/;
|
||||||
|
|
||||||
|
const downloadBlob = (blob: Blob, filename: string) => {
|
||||||
|
const url = URL.createObjectURL(blob);
|
||||||
|
const link = document.createElement("a");
|
||||||
|
link.href = url;
|
||||||
|
link.download = filename;
|
||||||
|
document.body.appendChild(link);
|
||||||
|
link.click();
|
||||||
|
link.remove();
|
||||||
|
URL.revokeObjectURL(url);
|
||||||
|
};
|
||||||
|
|
||||||
|
export function CustomerTruckAssignmentCard({
|
||||||
|
booking,
|
||||||
|
onAssigned,
|
||||||
|
}: {
|
||||||
|
booking: Freight.IBooking;
|
||||||
|
onAssigned: () => void;
|
||||||
|
}) {
|
||||||
|
const assigned = Boolean(booking.customerTruckAssignedAt);
|
||||||
|
const [truckPlateNumber, setTruckPlateNumber] = useState(booking.customerTruckPlateNumber ?? "");
|
||||||
|
const [driverName, setDriverName] = useState(booking.customerTruckDriverName ?? "");
|
||||||
|
const [truckType, setTruckType] = useState(booking.customerTruckType ?? "");
|
||||||
|
const [containerNumberToLoad, setContainerNumberToLoad] = useState(
|
||||||
|
booking.customerTruckContainerNumber ?? "",
|
||||||
|
);
|
||||||
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
|
||||||
|
const assignMutation = useMutation(api.bookings.assignCustomerTruck.mutationOptions());
|
||||||
|
const downloadMutation = useMutation(api.bookings.downloadCustomerTruckFreightOrder.mutationOptions());
|
||||||
|
|
||||||
|
const submit = async () => {
|
||||||
|
const payload = {
|
||||||
|
truckPlateNumber: truckPlateNumber.trim().toUpperCase(),
|
||||||
|
driverName: driverName.trim(),
|
||||||
|
truckType: truckType.trim(),
|
||||||
|
containerNumberToLoad: containerNumberToLoad.trim().toUpperCase(),
|
||||||
|
};
|
||||||
|
if (!payload.truckPlateNumber || !payload.driverName || !payload.truckType || !payload.containerNumberToLoad) {
|
||||||
|
setError("All truck assignment fields are required.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!ISO_CONTAINER_PATTERN.test(payload.containerNumberToLoad)) {
|
||||||
|
setError("Container number must match ISO format, e.g. ABCD1234567.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setError(null);
|
||||||
|
await assignMutation.mutateAsync({ id: booking.id, payload });
|
||||||
|
onAssigned();
|
||||||
|
};
|
||||||
|
|
||||||
|
const downloadFreightOrder = async () => {
|
||||||
|
const blob = await downloadMutation.mutateAsync({ id: booking.id });
|
||||||
|
downloadBlob(blob, `freight-order-${booking.reference}.pdf`);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<SectionCard>
|
||||||
|
<Stack gap="md">
|
||||||
|
<Group justify="space-between" align="center">
|
||||||
|
<Group gap={10}>
|
||||||
|
<Truck size={18} color="#0a9f6a" />
|
||||||
|
<CardTitle>External Truck Assignment</CardTitle>
|
||||||
|
</Group>
|
||||||
|
{assigned && (
|
||||||
|
<Group gap={6} c="#0a9f6a">
|
||||||
|
<Lock size={14} />
|
||||||
|
<Text size="sm" fw={700}>
|
||||||
|
Truck Assigned
|
||||||
|
</Text>
|
||||||
|
</Group>
|
||||||
|
)}
|
||||||
|
</Group>
|
||||||
|
|
||||||
|
{error && (
|
||||||
|
<Alert color="red" variant="light">
|
||||||
|
{error}
|
||||||
|
</Alert>
|
||||||
|
)}
|
||||||
|
{assignMutation.isError && (
|
||||||
|
<Alert color="red" variant="light">
|
||||||
|
{assignMutation.error instanceof Error
|
||||||
|
? assignMutation.error.message
|
||||||
|
: "Truck assignment failed."}
|
||||||
|
</Alert>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<SimpleGrid cols={{ base: 1, sm: 2 }} spacing="sm">
|
||||||
|
<TextInput
|
||||||
|
label="Truck Plate Number"
|
||||||
|
required
|
||||||
|
value={truckPlateNumber}
|
||||||
|
onChange={(e) => setTruckPlateNumber(e.currentTarget.value)}
|
||||||
|
readOnly={assigned}
|
||||||
|
/>
|
||||||
|
<TextInput
|
||||||
|
label="Driver Name"
|
||||||
|
required
|
||||||
|
value={driverName}
|
||||||
|
onChange={(e) => setDriverName(e.currentTarget.value)}
|
||||||
|
readOnly={assigned}
|
||||||
|
/>
|
||||||
|
<Select
|
||||||
|
label="Truck Type"
|
||||||
|
required
|
||||||
|
data={TRUCK_TYPES}
|
||||||
|
value={truckType || null}
|
||||||
|
onChange={(value) => setTruckType(value ?? "")}
|
||||||
|
disabled={assigned}
|
||||||
|
/>
|
||||||
|
<TextInput
|
||||||
|
label="Container Number to Load"
|
||||||
|
required
|
||||||
|
value={containerNumberToLoad}
|
||||||
|
onChange={(e) => setContainerNumberToLoad(e.currentTarget.value.toUpperCase())}
|
||||||
|
readOnly={assigned}
|
||||||
|
/>
|
||||||
|
</SimpleGrid>
|
||||||
|
|
||||||
|
<Group justify="flex-end">
|
||||||
|
{assigned ? (
|
||||||
|
<Button
|
||||||
|
leftSection={<Download size={16} />}
|
||||||
|
color="edr-green"
|
||||||
|
onClick={downloadFreightOrder}
|
||||||
|
loading={downloadMutation.isPending}
|
||||||
|
>
|
||||||
|
Generate Freight Order Copies
|
||||||
|
</Button>
|
||||||
|
) : (
|
||||||
|
<Button color="edr-green" onClick={submit} loading={assignMutation.isPending}>
|
||||||
|
Verify & Submit Assignment
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</Group>
|
||||||
|
</Stack>
|
||||||
|
</SectionCard>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -94,5 +94,5 @@ export default function BookingDetailPage() {
|
|||||||
<DraftBookingView booking={booking} onBookingUpdated={refetchBooking} />
|
<DraftBookingView booking={booking} onBookingUpdated={refetchBooking} />
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return <ReadonlyBookingView booking={booking} />;
|
return <ReadonlyBookingView booking={booking} onBookingUpdated={refetchBooking} />;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,17 @@ const errorMessage = (error: unknown) => {
|
|||||||
return error instanceof Error ? error.message : "Could not approve delivery";
|
return error instanceof Error ? error.message : "Could not approve delivery";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const downloadBlob = (blob: Blob, filename: string) => {
|
||||||
|
const url = URL.createObjectURL(blob);
|
||||||
|
const link = document.createElement("a");
|
||||||
|
link.href = url;
|
||||||
|
link.download = filename;
|
||||||
|
document.body.appendChild(link);
|
||||||
|
link.click();
|
||||||
|
link.remove();
|
||||||
|
URL.revokeObjectURL(url);
|
||||||
|
};
|
||||||
|
|
||||||
export function ApproveDeliveryButton({
|
export function ApproveDeliveryButton({
|
||||||
bookingId,
|
bookingId,
|
||||||
stopPropagation,
|
stopPropagation,
|
||||||
@@ -32,10 +43,19 @@ export function ApproveDeliveryButton({
|
|||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
const handoverMutation = useMutation(api.bookings.downloadHandoverDocument.mutationOptions());
|
||||||
|
|
||||||
const mutation = useMutation({
|
const mutation = useMutation({
|
||||||
...api.bookings.approveDelivery.mutationOptions(),
|
...api.bookings.approveDelivery.mutationOptions(),
|
||||||
onSuccess: async () => {
|
onSuccess: async (result) => {
|
||||||
toast.success("Delivery approved and handover signed");
|
try {
|
||||||
|
const blob = await handoverMutation.mutateAsync({ inventoryId: result.inventoryId });
|
||||||
|
downloadBlob(blob, `handover-${bookingId}.pdf`);
|
||||||
|
toast.success("Delivery approved and signed handover downloaded");
|
||||||
|
} catch {
|
||||||
|
toast.success("Delivery approved and handover signed");
|
||||||
|
toast.error("Signed handover document could not be downloaded");
|
||||||
|
}
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
queryClient.invalidateQueries({ queryKey: api.bookings.get.queryKey({ id: bookingId }) }),
|
queryClient.invalidateQueries({ queryKey: api.bookings.get.queryKey({ id: bookingId }) }),
|
||||||
queryClient.invalidateQueries({ queryKey: api.bookings.list.queryKey() }),
|
queryClient.invalidateQueries({ queryKey: api.bookings.list.queryKey() }),
|
||||||
@@ -48,6 +68,8 @@ export function ApproveDeliveryButton({
|
|||||||
toast.error(message);
|
toast.error(message);
|
||||||
if (message.toLowerCase().includes("save your signature")) {
|
if (message.toLowerCase().includes("save your signature")) {
|
||||||
navigate("/signature");
|
navigate("/signature");
|
||||||
|
} else if (/demurrage|storage|warehouse invoice|fully paid/i.test(message)) {
|
||||||
|
navigate("/billing");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@@ -64,7 +86,7 @@ export function ApproveDeliveryButton({
|
|||||||
variant={variant}
|
variant={variant}
|
||||||
color="edr-green"
|
color="edr-green"
|
||||||
leftSection={<CheckCircle2 size={16} />}
|
leftSection={<CheckCircle2 size={16} />}
|
||||||
loading={mutation.isPending}
|
loading={mutation.isPending || handoverMutation.isPending}
|
||||||
onClick={handleClick}
|
onClick={handleClick}
|
||||||
>
|
>
|
||||||
Approve delivery
|
Approve delivery
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import {
|
|||||||
type ApproveDeliveryResponse,
|
type ApproveDeliveryResponse,
|
||||||
BookingListFilter,
|
BookingListFilter,
|
||||||
CreateBookingPayload,
|
CreateBookingPayload,
|
||||||
|
type CustomerTruckAssignmentPayload,
|
||||||
GeneratePriceResponse,
|
GeneratePriceResponse,
|
||||||
SubmitBookingResponse,
|
SubmitBookingResponse,
|
||||||
} from "./bookings.service";
|
} from "./bookings.service";
|
||||||
@@ -210,6 +211,25 @@ export const api = {
|
|||||||
({ id }) => bookingsService.tracking(id),
|
({ id }) => bookingsService.tracking(id),
|
||||||
),
|
),
|
||||||
|
|
||||||
|
assignCustomerTruck: endpoint<
|
||||||
|
{ id: string; payload: CustomerTruckAssignmentPayload },
|
||||||
|
Freight.IBooking
|
||||||
|
>("bookings", "assignCustomerTruck", ({ id, payload }) =>
|
||||||
|
bookingsService.assignCustomerTruck(id, payload),
|
||||||
|
),
|
||||||
|
|
||||||
|
downloadCustomerTruckFreightOrder: endpoint<{ id: string }, Blob>(
|
||||||
|
"bookings",
|
||||||
|
"downloadCustomerTruckFreightOrder",
|
||||||
|
({ id }) => bookingsService.downloadCustomerTruckFreightOrder(id),
|
||||||
|
),
|
||||||
|
|
||||||
|
downloadHandoverDocument: endpoint<{ inventoryId: string }, Blob>(
|
||||||
|
"bookings",
|
||||||
|
"downloadHandoverDocument",
|
||||||
|
({ inventoryId }) => bookingsService.downloadHandoverDocument(inventoryId),
|
||||||
|
),
|
||||||
|
|
||||||
create: endpoint<
|
create: endpoint<
|
||||||
{ payload: CreateBookingPayload; documents?: BookingDocuments },
|
{ payload: CreateBookingPayload; documents?: BookingDocuments },
|
||||||
Freight.IBooking
|
Freight.IBooking
|
||||||
|
|||||||
@@ -79,6 +79,13 @@ export interface ApproveDeliveryResponse {
|
|||||||
signerDisplayName: string;
|
signerDisplayName: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface CustomerTruckAssignmentPayload {
|
||||||
|
truckPlateNumber: string;
|
||||||
|
driverName: string;
|
||||||
|
truckType: string;
|
||||||
|
containerNumberToLoad: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface BookingListFilter {
|
export interface BookingListFilter {
|
||||||
status?: string;
|
status?: string;
|
||||||
/** Comma-separated statuses (overrides `status` when set). */
|
/** Comma-separated statuses (overrides `status` when set). */
|
||||||
@@ -111,6 +118,30 @@ export const bookingsService = {
|
|||||||
const { data } = await client.get(`/api/bookings/${id}`);
|
const { data } = await client.get(`/api/bookings/${id}`);
|
||||||
return data.data;
|
return data.data;
|
||||||
},
|
},
|
||||||
|
assignCustomerTruck: async (
|
||||||
|
id: string,
|
||||||
|
payload: CustomerTruckAssignmentPayload,
|
||||||
|
): Promise<Freight.IBooking> => {
|
||||||
|
const { data } = await client.post(
|
||||||
|
`/api/bookings/${id}/customer-truck-assignment`,
|
||||||
|
payload,
|
||||||
|
);
|
||||||
|
return data.data;
|
||||||
|
},
|
||||||
|
downloadCustomerTruckFreightOrder: async (id: string): Promise<Blob> => {
|
||||||
|
const { data } = await client.get(
|
||||||
|
`/api/bookings/${id}/customer-truck-assignment/freight-order`,
|
||||||
|
{ responseType: "blob" },
|
||||||
|
);
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
downloadHandoverDocument: async (inventoryId: string): Promise<Blob> => {
|
||||||
|
const { data } = await client.get(
|
||||||
|
`/api/warehouse-inventory/${inventoryId}/handover-document`,
|
||||||
|
{ responseType: "blob" },
|
||||||
|
);
|
||||||
|
return data;
|
||||||
|
},
|
||||||
tracking: async (id: string): Promise<Freight.IBookingTracking> => {
|
tracking: async (id: string): Promise<Freight.IBookingTracking> => {
|
||||||
const { data } = await client.get(`/api/bookings/${id}/tracking`);
|
const { data } = await client.get(`/api/bookings/${id}/tracking`);
|
||||||
return data.data;
|
return data.data;
|
||||||
|
|||||||
@@ -91,6 +91,7 @@ export enum BookingStatus {
|
|||||||
Cancelled = "CANCELLED",
|
Cancelled = "CANCELLED",
|
||||||
PendingConsolidation = "PENDING_CONSOLIDATION",
|
PendingConsolidation = "PENDING_CONSOLIDATION",
|
||||||
Consolidated = "CONSOLIDATED",
|
Consolidated = "CONSOLIDATED",
|
||||||
|
TruckAssigned = "TRUCK_ASSIGNED",
|
||||||
/** General contract: paid umbrella contract that is accepting drawdown orders. */
|
/** General contract: paid umbrella contract that is accepting drawdown orders. */
|
||||||
ContractActive = "CONTRACT_ACTIVE",
|
ContractActive = "CONTRACT_ACTIVE",
|
||||||
/** General contract: closed because its quantity was exhausted (or period elapsed). */
|
/** General contract: closed because its quantity was exhausted (or period elapsed). */
|
||||||
@@ -420,6 +421,12 @@ export interface IBooking extends BaseEntity {
|
|||||||
lastMileDeliveryAddress?: string | null;
|
lastMileDeliveryAddress?: string | null;
|
||||||
lastMileDeliveryLat?: number | null;
|
lastMileDeliveryLat?: number | null;
|
||||||
lastMileDeliveryLng?: number | null;
|
lastMileDeliveryLng?: number | null;
|
||||||
|
customerTruckPlateNumber?: string | null;
|
||||||
|
customerTruckDriverName?: string | null;
|
||||||
|
customerTruckType?: string | null;
|
||||||
|
customerTruckContainerNumber?: string | null;
|
||||||
|
customerTruckAssignedAt?: string | null;
|
||||||
|
customerTruckArrivedAt?: string | null;
|
||||||
|
|
||||||
customsClearingEnabled?: boolean;
|
customsClearingEnabled?: boolean;
|
||||||
customsClearingAgent?: string | null;
|
customsClearingAgent?: string | null;
|
||||||
|
|||||||
Reference in New Issue
Block a user