From 8cf49aa1cc09bc0331d52628fc6a38d5640a9a1f Mon Sep 17 00:00:00 2001 From: Marshal Date: Tue, 4 Aug 2026 13:06:03 +0000 Subject: [PATCH] enhance contract document rendering with detailed cargo information - Updated ContractDocumentViewModelBuilder to include cargoTypeName, containerType, and cargoSummary in the schedule. - Modified contract dynamic template tests to validate the new cargo fields. - Enhanced contract renderer service tests to reflect changes in cargo data structure. - Updated contract view model interface to include new cargo-related fields. - Improved dynamic template rendering to display cargo type and container type. - Refactored exchange settings controller and service to streamline error handling and feed status management. - Introduced article HTML conversion functions to support Quill editor integration for structured article editing. - Added tests for article HTML conversion to ensure correct round-trip processing of clauses and bullets. --- .../contract-dynamic-template.spec.ts | 20 +++++++++++++++++++ .../contract-renderer.service.spec.ts | 2 ++ .../contracts/contract-view-model.builder.ts | 2 ++ .../src/contracts/templates/edr-dynamic.hbs | 6 ++++++ .../contract-templates.service.ts | 3 +++ .../ContractTemplateEditorPage.tsx | 12 +++++++++++ 6 files changed, 45 insertions(+) diff --git a/apps/edr-freight-api/src/contracts/contract-dynamic-template.spec.ts b/apps/edr-freight-api/src/contracts/contract-dynamic-template.spec.ts index b0e0e4d3d..b840cb032 100644 --- a/apps/edr-freight-api/src/contracts/contract-dynamic-template.spec.ts +++ b/apps/edr-freight-api/src/contracts/contract-dynamic-template.spec.ts @@ -90,6 +90,8 @@ describe('dynamic template rendering (edr-dynamic.hbs)', () => { template: { ...meta, title: 'Bulk Import Contract', templateFile: 'edr-dynamic.hbs' }, contractDate: '1 January 2026', contractYear: 2026, + contractStartDate: '1 January 2026', + contractEndDate: '31 December 2026', client: { companyName: 'Abyssinia Trading PLC', companyAddress: 'Bole Sub-city, Addis Ababa', @@ -195,6 +197,24 @@ describe('dynamic template rendering (edr-dynamic.hbs)', () => { expect(html).toContain('#1b9e7a'); }); + it('shows the contract validity window in the commercial schedule annex', () => { + const html = renderer.render(dynamicView()); + expect(html).toContain('Valid from'); + expect(html).toContain('Valid until'); + expect(html).toContain('1 January 2026'); + expect(html).toContain('31 December 2026'); + }); + + it('interpolates the start/end date placeholders inside article text', () => { + const view = dynamicView(); + expect( + interpolateTemplateText( + 'In force {{contractStartDate}} to {{contractEndDate}}.', + view, + ), + ).toBe('In force 1 January 2026 to 31 December 2026.'); + }); + it('shows cargo type and container type in the commercial schedule annex', () => { const html = renderer.render(dynamicView()); expect(html).toContain('Cargo type'); diff --git a/apps/edr-freight-api/src/contracts/contract-renderer.service.spec.ts b/apps/edr-freight-api/src/contracts/contract-renderer.service.spec.ts index 79f5e2f73..fc7e66e5b 100644 --- a/apps/edr-freight-api/src/contracts/contract-renderer.service.spec.ts +++ b/apps/edr-freight-api/src/contracts/contract-renderer.service.spec.ts @@ -16,6 +16,8 @@ describe('ContractRendererService', () => { template, contractDate: '1 January 2026', contractYear: 2026, + contractStartDate: '1 January 2026', + contractEndDate: '31 December 2026', client: { companyName: 'Test Co', companyAddress: 'Addis Ababa', diff --git a/apps/edr-freight-api/src/contracts/contract-view-model.builder.ts b/apps/edr-freight-api/src/contracts/contract-view-model.builder.ts index d874fb792..d1158d035 100644 --- a/apps/edr-freight-api/src/contracts/contract-view-model.builder.ts +++ b/apps/edr-freight-api/src/contracts/contract-view-model.builder.ts @@ -150,6 +150,8 @@ export class ContractViewModelBuilder { year: 'numeric', }), contractYear: new Date().getFullYear(), + contractStartDate: this.formatDate(booking.contractValidFrom), + contractEndDate: this.formatDate(booking.contractValidUntil), client: { companyName: booking.company?.name ?? 'Client', companyAddress: this.valueOrDash(booking.company?.address), diff --git a/apps/edr-freight-api/src/contracts/templates/edr-dynamic.hbs b/apps/edr-freight-api/src/contracts/templates/edr-dynamic.hbs index 5c4c4052b..6ba7c1610 100644 --- a/apps/edr-freight-api/src/contracts/templates/edr-dynamic.hbs +++ b/apps/edr-freight-api/src/contracts/templates/edr-dynamic.hbs @@ -143,6 +143,12 @@ Payment currency {{paymentArticle}} + + Valid from + {{contractStartDate}} + Valid until + {{contractEndDate}} + diff --git a/apps/edr-freight-api/src/modules/contract-templates/contract-templates.service.ts b/apps/edr-freight-api/src/modules/contract-templates/contract-templates.service.ts index e94f9470f..ea41b57a2 100644 --- a/apps/edr-freight-api/src/modules/contract-templates/contract-templates.service.ts +++ b/apps/edr-freight-api/src/modules/contract-templates/contract-templates.service.ts @@ -208,6 +208,9 @@ export class ContractTemplatesService { year: "numeric", }), contractYear: now.getFullYear(), + // Representative validity window for the admin preview only. + contractStartDate: `1 January ${now.getFullYear()}`, + contractEndDate: `31 December ${now.getFullYear()}`, client: { companyName: "Abyssinia Trading PLC", companyAddress: "Bole Sub-city, Woreda 03, H.No 1234, Addis Ababa", diff --git a/apps/edr-freight-web/backoffice/src/pages/contract_templates/ContractTemplateEditorPage.tsx b/apps/edr-freight-web/backoffice/src/pages/contract_templates/ContractTemplateEditorPage.tsx index 240a92a13..027bdae74 100644 --- a/apps/edr-freight-web/backoffice/src/pages/contract_templates/ContractTemplateEditorPage.tsx +++ b/apps/edr-freight-web/backoffice/src/pages/contract_templates/ContractTemplateEditorPage.tsx @@ -109,6 +109,18 @@ const QUICK_PLACEHOLDERS: PlaceholderDef[] = [ icon: CalendarRange, hint: "Year the contract is signed", }, + { + token: "{{contractStartDate}}", + label: "Start date", + icon: CalendarClock, + hint: "Date the contract's validity begins", + }, + { + token: "{{contractEndDate}}", + label: "End date", + icon: CalendarClock, + hint: "Date the contract's validity ends", + }, ]; const MORE_PLACEHOLDER_GROUPS: { label: string; items: PlaceholderDef[] }[] = [