diff --git a/apps/edr-freight-api/src/modules/bookings/bookings.module.ts b/apps/edr-freight-api/src/modules/bookings/bookings.module.ts index 4b3e3bcca..96ed3b701 100644 --- a/apps/edr-freight-api/src/modules/bookings/bookings.module.ts +++ b/apps/edr-freight-api/src/modules/bookings/bookings.module.ts @@ -11,6 +11,7 @@ import { RuleEngineModule } from '../rule-engine/rule-engine.module'; import { FileUploadSettingsModule } from '../file-upload-settings/file-upload-settings.module'; import { SignaturesModule } from '../signatures/signatures.module'; import { BillingModule } from '../billing/billing.module'; +import { DocumentsModule } from '../billing/documents/documents.module'; import { FirstMileModule } from '../first-mile/first-mile.module'; import { LastMileModule } from '../last-mile/last-mile.module'; import { BookingContractService } from './booking-contract.service'; @@ -68,6 +69,7 @@ import { VehiclesModule } from "../vehicles/vehicles.module"; CustomerTruckContainer, ]), BillingModule, + DocumentsModule, NotificationsModule, NotificationInboxModule, forwardRef(() => FirstMileModule), diff --git a/apps/edr-freight-api/src/modules/bookings/bookings.service.ts b/apps/edr-freight-api/src/modules/bookings/bookings.service.ts index dac739fbf..9f72c7409 100644 --- a/apps/edr-freight-api/src/modules/bookings/bookings.service.ts +++ b/apps/edr-freight-api/src/modules/bookings/bookings.service.ts @@ -50,7 +50,8 @@ import { Booking } from './entities/booking.entity'; import { BookingContainerAllocation } from './entities/booking-container-allocation.entity'; import { FileRecord } from '../files/entities/file.entity'; import { CustomerTruckAssignmentDto } from './dto/customer-truck-assignment.dto'; -import { ContractPdfService } from '../../contracts/contract-pdf.service'; +import { PdfRenderService } from '../billing/documents/pdf-render.service'; +import { buildTabularFallbackPdf } from '../billing/documents/styled-pdf.util'; /** Paginated booking list: flat `total` (backoffice) + `meta` block (portal). */ export interface PaginatedBookings { @@ -99,7 +100,7 @@ export class BookingsService { private readonly containerTypesService: ContainerTypesService, private readonly consolidationService: ConsolidationService, private readonly vehiclesService: VehiclesService, - private readonly contractPdfService: ContractPdfService, + private readonly pdfRender: PdfRenderService, private readonly events: EventEmitter2, ) {} @@ -170,7 +171,12 @@ export class BookingsService { ); const html = this.buildCustomerTruckFreightOrderHtml(booking, trucks); - const buffer = await this.contractPdfService.htmlToPdfBuffer(html); + // Chromium when available; otherwise the styled tabular fallback (never the + // generic text dump — the freight order is an outward-facing gate document). + const buffer = await this.pdfRender.htmlToPdfBuffer(html, { + label: 'freight order', + fallback: (prepared) => buildTabularFallbackPdf(prepared), + }); return { filename: `freight-order-${booking.reference.replace(/[^a-zA-Z0-9_-]+/g, '-')}.pdf`, buffer, @@ -262,21 +268,10 @@ export class BookingsService { containers: string | null; }>, ): string { + const esc = (v: unknown) => this.escapeHtml(String(v ?? '-')); const assignedAt = booking.customerTruckAssignedAt ? new Date(booking.customerTruckAssignedAt).toLocaleString('en-GB') : '-'; - const bookingRows: 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], - ['Assigned At', assignedAt], - ['Booking Status', booking.status], - ]; - const bookingRowHtml = bookingRows - .map(([label, value]) => `
Customer external truck assignment — ${truckList.length} truck${truckList.length !== 1 ? 's' : ''}
+| # | +Truck plate | +Driver | +Truck type | +Containers loaded | +Arrival | +
|---|