From 31a2e93c4918f36f78a04361afeea1f527fe12f9 Mon Sep 17 00:00:00 2001 From: Nathnael Date: Mon, 29 Jun 2026 14:42:53 +0000 Subject: [PATCH] fix: rm the hardcode false for general contract --- .../bookings/booking-invoice.service.ts | 52 ++++--------------- .../src/modules/bookings/bookings.module.ts | 2 - 2 files changed, 9 insertions(+), 45 deletions(-) diff --git a/apps/edr-freight-api/src/modules/bookings/booking-invoice.service.ts b/apps/edr-freight-api/src/modules/bookings/booking-invoice.service.ts index 6cd2f4be5..47338f196 100644 --- a/apps/edr-freight-api/src/modules/bookings/booking-invoice.service.ts +++ b/apps/edr-freight-api/src/modules/bookings/booking-invoice.service.ts @@ -10,7 +10,6 @@ import { InvoiceLineInput, } from '../billing/billing.service'; import { Invoice } from '../billing/entities/invoice.entity'; -import { DropdownSettingsService } from '../dropdown-settings/dropdown-settings.service'; import { FirstMileService } from '../first-mile/first-mile.service'; import { BookingBatchService } from '../train-scheduling/booking-batch.service'; import { PriceLineItemDto } from './dto/generate-price-response.dto'; @@ -27,10 +26,6 @@ interface StoredPricingBreakdown { /** Round to 2 decimals, avoiding binary float drift. */ const round2 = (n: number): number => Math.round(n * 100) / 100; -/** Setting code holding the general-contract ordering window (months). */ -const CONTRACT_PERIOD_SETTING_CODE = 'general_contract_period'; -const DEFAULT_CONTRACT_PERIOD_MONTHS = 3; - /** * Owns the booking ⇄ invoice mapping — the one place that knows how a booking * turns into invoices, which type to use, and how it advances when paid. Bookings @@ -47,7 +42,6 @@ export class BookingInvoiceService { private readonly billing: BillingService, private readonly bookingsRepository: BookingsRepository, private readonly dataSource: DataSource, - private readonly dropdownSettings: DropdownSettingsService, @Inject(forwardRef(() => FirstMileService)) private readonly firstMile: FirstMileService, @Inject(forwardRef(() => BookingBatchService)) @@ -107,11 +101,15 @@ export class BookingInvoiceService { } /** - * Advance a booking once its prepaid invoice settles. This is the domain - * side-effect of payment, relocated out of the payment service: a general - * contract becomes ACTIVE and opens its ordering window (it does not enter the - * train queue — nothing has been ordered yet); a normal booking becomes PAID + * Advance a booking once its prepaid invoice settles — the domain side-effect + * of payment, relocated out of the payment service: the booking becomes PAID * and is allocated into its batch. Idempotent — no-op when already PAID. + * + * General contracts are a separate aggregate now: their CONTRACT_ACTIVE + * lifecycle and ordering window live in the contracts module, advanced by the + * contract transition/clearance services — not by booking payment. Every + * booking that settles here is a ONE_TIME shipment, so there is no contract + * branch (legacy GENERAL_CONTRACT booking creation now 410s). */ private async advanceBookingOnPayment(bookingId: string): Promise { const booking = await this.bookingsRepository.findById(bookingId); @@ -121,35 +119,15 @@ export class BookingInvoiceService { } if (booking.paymentStatus === 'PAID') return; - const paidAt = new Date(); - const isGeneralContract = false - // booking.bookingType === 'GENERAL_CONTRACT'; - - let contractExpiresAt: Date | null = null; - if (isGeneralContract) { - const months = await this.contractPeriodMonths(); - contractExpiresAt = new Date(paidAt); - contractExpiresAt.setMonth(contractExpiresAt.getMonth() + months); - } - await this.dataSource.transaction(async (mg) => { await mg.update( Booking, { id: bookingId }, - isGeneralContract - ? { paymentStatus: 'PAID', status: 'CONTRACT_ACTIVE', expiresAt: contractExpiresAt } - : { paymentStatus: 'PAID', status: 'PAID' }, + { paymentStatus: 'PAID', status: 'PAID' }, ); await this.firstMile.acceptBooking(bookingId); }); - if (isGeneralContract) { - this.logger.log( - `General contract ${booking.reference} ACTIVE — ordering open until ${contractExpiresAt?.toISOString()}`, - ); - return; - } - try { await this.bookingBatch.ensurePaidBookingAllocated(bookingId); } catch (err) { @@ -159,18 +137,6 @@ export class BookingInvoiceService { } } - /** Configured general-contract ordering window in months (defaults to 3). */ - private async contractPeriodMonths(): Promise { - try { - const setting = await this.dropdownSettings.getByCode(CONTRACT_PERIOD_SETTING_CODE); - const months = Number(setting.children?.[0]?.value); - if (Number.isFinite(months) && months > 0) return months; - } catch { - // Setting not seeded — fall back to the default. - } - return DEFAULT_CONTRACT_PERIOD_MONTHS; - } - /** Map a booking's pricing snapshot into a generic invoice request. */ private buildInput(booking: Booking): GenerateInvoiceInput | null { const breakdown = (booking.pricingBreakdown ?? {}) as StoredPricingBreakdown; 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 1a12a5e6f..8be7325ba 100644 --- a/apps/edr-freight-api/src/modules/bookings/bookings.module.ts +++ b/apps/edr-freight-api/src/modules/bookings/bookings.module.ts @@ -11,7 +11,6 @@ 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 { DropdownSettingsModule } from '../dropdown-settings/dropdown-settings.module'; import { FirstMileModule } from '../first-mile/first-mile.module'; import { BookingContractService } from './booking-contract.service'; import { BookingInvoiceService } from './booking-invoice.service'; @@ -53,7 +52,6 @@ import { TrainSchedulingModule } from '../train-scheduling/train-scheduling.modu BookingContractSignature, ]), BillingModule, - DropdownSettingsModule, forwardRef(() => FirstMileModule), forwardRef(() => TrainSchedulingModule), FilesModule,