fix: rm the hardcode false for general contract

This commit is contained in:
Nathnael
2026-06-29 14:42:53 +00:00
parent feae27d0c3
commit 31a2e93c49
2 changed files with 9 additions and 45 deletions

View File

@@ -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<void> {
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<number> {
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;

View File

@@ -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,