fix: premature payable invoice

This commit is contained in:
Nathnael
2026-07-16 08:38:49 +00:00
parent 5f6d8f9294
commit 6dde17fa4d
5 changed files with 167 additions and 26 deletions

View File

@@ -134,7 +134,7 @@ describe('BookingBatchService — PAID reconcile', () => {
{ addTimeout: jest.fn(), deleteTimeout: jest.fn(), doesExist: jest.fn() } as never,
trainSchedulingService as never,
{
syncPayableDueDate: jest.fn().mockResolvedValue(undefined),
issuePayable: jest.fn().mockResolvedValue(null),
expirePayable: jest.fn().mockResolvedValue(undefined),
} as never,
{ emitPhase: jest.fn() } as never,
@@ -596,7 +596,7 @@ describe('BookingBatchService — PAID reconcile', () => {
notifier as never,
{ addTimeout: jest.fn(), deleteTimeout: jest.fn(), doesExist: jest.fn() } as never,
trainSchedulingService as never,
{ syncPayableDueDate: jest.fn(), expirePayable: jest.fn() } as never,
{ issuePayable: jest.fn(), expirePayable: jest.fn() } as never,
{ emitPhase: jest.fn() } as never,
{ computeSubmitPriorityScore: jest.fn().mockResolvedValue(0) } as never,
undefined,
@@ -619,7 +619,7 @@ describe('BookingBatchService — PAID reconcile', () => {
notifier as never,
{ addTimeout: jest.fn(), deleteTimeout: jest.fn(), doesExist: jest.fn() } as never,
trainSchedulingService as never,
{ syncPayableDueDate: jest.fn(), expirePayable: jest.fn() } as never,
{ issuePayable: jest.fn(), expirePayable: jest.fn() } as never,
{ emitPhase: jest.fn() } as never,
{ computeSubmitPriorityScore: jest.fn().mockResolvedValue(0) } as never,
undefined,
@@ -650,7 +650,7 @@ describe('BookingBatchService — PAID reconcile', () => {
notifier as never,
{ addTimeout: jest.fn(), deleteTimeout: jest.fn(), doesExist: jest.fn() } as never,
trainSchedulingService as never,
{ syncPayableDueDate: jest.fn(), expirePayable: jest.fn() } as never,
{ issuePayable: jest.fn(), expirePayable: jest.fn() } as never,
{ emitPhase: jest.fn() } as never,
{ computeSubmitPriorityScore: jest.fn().mockResolvedValue(0) } as never,
undefined,

View File

@@ -2317,9 +2317,13 @@ export class BookingBatchService implements OnModuleInit {
paymentDeadline: deadline,
} as never);
booking.trainScheduleId = scheduleId;
// The invoice was generated at booking creation/approval, before this pay
// window opened — refresh its printed due date to the real deadline.
await this.billing.syncPayableDueDate(
// The invoice was generated DRAFT at booking creation / operation-accept,
// before this pay window existed. Reserving is the moment the booking becomes
// payable (SELECTED_FOR_BATCH + a real deadline), so issue the draft here and
// print the deadline as its due date — never earlier, or the customer could
// settle an invoice for a slot they have not been offered yet. Idempotent: a
// re-reserve only refreshes `dueAt`.
await this.billing.issuePayable(
Freight.InvoiceSource.Booking,
booking.id,
deadline,