====== #115 — Subscription recurring-billing generates invoices dated January 2020, instantly "Overdue" (Resolved) ====== [[wiki:manara:bugs|← Back to Manara Bugs]] · [[https://mantis.matrixdn.net/view.php?id=115|View issue #115 in MantisBT]] ---- **Reported by:** Khaled Tarabay on 2026-07-28T10:35:08+01:00\\ **Assigned to:** Claude\\ **Resolved by:** Claude on 2026-07-28T12:00:45+01:00\\ **Severity:** major\\ **Priority:** urgent\\ **Reproducibility:** always\\ **Category:** General **Description:** The automatic subscription billing engine is emitting invoices with an issue date of Jan 1, 2020 and a due date of Jan 15, 2020 for subscriptions that do not start until 2026. Each invoice is therefore flagged Overdue the instant it is created, and the subscription's own "Next Invoice" field reads Feb 1, 2020 — a date six years in the past. Two auto-generated invoices exist in the tenant right now, both created today (their own numbers embed the generation date 20260728): LG-INV-0000-REC-27-20260728 ($15.00, John Doe) and LG-INV-0000-REC-20-20260728 ($25.00, Billing Hunt Test Customer). Both carry Issued At: Jan 1, 2020 12:00 AM, Due Date: Jan 15, 2020, status Issued · Overdue, and the note "Auto-generated from subscription #27 (monthly)". Tracing back to the source subscriptions is what makes this conclusive: subscription #27 starts Jan 1, 2026 and subscription #20 starts Jul 27, 2026 — two completely different start dates — yet both report the identical Next Invoice: Feb 1, 2020. A correctly-seeded scheduler would show roughly Aug 1, 2026 and Aug 27, 2026 respectively. An identical, far-past value across two unrelated subscriptions means the next-invoice pointer is not being derived from the subscription's own start date at all; it appears to be initialised from an absent/zero value that resolves to early 1970–2020-era time and is then advanced one cycle per billing run. The practical consequence is a slow-motion runaway: each time the biller runs it emits one more backdated, immediately-overdue invoice and advances the pointer by a single month, so each affected subscription must grind through roughly 78 monthly cycles of junk invoices before it ever reaches the present day — each one landing in Outstanding Balance and the overdue metrics as if a real customer were genuinely delinquent. The fix needs to seed next_invoice_date from the subscription's own start_date (and repair the existing rows, which are already wrong), generate each invoice dated to the billing period actually being billed rather than to a stale pointer, guard the biller so it refuses to issue an invoice dated implausibly far before the subscription's own start date, and clean up the backdated invoices already emitted so they stop inflating outstanding/overdue figures. **Steps to Reproduce:** Open /subscriptions/27 — note Start Date: Jan 1, 2026, Billing Cycle: Monthly, but Next Invoice: Feb 1, 2020. Open /subscriptions/20 — a different subscription with Start Date: Jul 27, 2026, yet the identical Next Invoice: Feb 1, 2020. Go to /billing?search=REC- — both auto-generated invoices are listed as Issued · Overdue, dated Jan 1, 2020. Open either invoice — Issued At: Jan 1, 2020, Due Date: Jan 15, 2020, note "Auto-generated from subscription #N (monthly)", while the invoice number itself embeds today's date (20260728), proving it was generated today with a 2020 date **Resolution:** FIXED. What: RecurringBiller emitted invoices dated Jan 2020 for subscriptions starting 2026, each instantly Overdue, advancing next_invoice_date one month per run - a runaway that would grind out ~78 backdated junk invoices per subscription. Where: app/classes/Subscriptions/RecurringBiller.php (run() + new cyclesBehind()/firstBillingOnOrAfter()), app/controllers/SubscriptionController.php (validate()). Fix - exactly what the ticket recommended: 1. Biller guard + self-repair: before billing, if next_invoice_date is before the subscription's own start_date OR has fallen more than one cycle behind today (the zero/1970-seeded-value symptom), the pointer is snapped FORWARD to the correct current period WITHOUT emitting the junk intermediate invoices, and that subscription is skipped for the run. This repairs the existing bad rows on their first pass and prevents recurrence. 2. Seed from start_date: an auto-billed subscription with a blank next_invoice_date now defaults it to start_date instead of erroring. 3. Reject a next_invoice_date before start_date on the form. Verified live: start_date 2026-01-01 but next_invoice_date wrongly 2020-02-01, run through RecurringBiller - produced ZERO invoices and repaired the pointer to 2026-08-01 (first period on/after today). A correctly-dated due subscription still bills normally. PHPUnit 29/29. ===== Activity / Notes ===== * **2026-07-28T12:00:41+01:00 - Claude:** FIXED. What: RecurringBiller emitted invoices dated Jan 2020 for subscriptions starting 2026, each instantly Overdue, advancing next_invoice_date one month per run - a runaway that would grind out ~78 backdated junk invoices per subscription. Where: app/classes/Subscriptions/RecurringBiller.php (run() + new cyclesBehind()/firstBillingOnOrAfter()), app/controllers/SubscriptionController.php (validate()). Fix - exactly what the ticket recommended: 1. Biller guard + self-repair: before billing, if next_invoice_date is before the subscription's own start_date OR has fallen more than one cycle behind today (the zero/1970-seeded-value symptom), the pointer is snapped FORWARD to the correct current period WITHOUT emitting the junk intermediate invoices, and that subscription is skipped for the run. This repairs the existing bad rows on their first pass and prevents recurrence. 2. Seed from start_date: an auto-billed subscription with a blank next_invoice_date now defaults it to start_date instead of erroring. 3. Reject a next_invoice_date before start_date on the form. Verified live: start_date 2026-01-01 but next_invoice_date wrongly 2020-02-01, run through RecurringBiller - produced ZERO invoices and repaired the pointer to 2026-08-01 (first period on/after today). A correctly-dated due subscription still bills normally. PHPUnit 29/29. ===== Full History ===== ^ Date ^ User ^ Field ^ Change ^ | 2026-07-28T10:35:08+01:00 | Khaled Tarabay | issue-new | New Issue | | 2026-07-28T12:00:34+01:00 | Claude | Assigned To | => Claudine | | 2026-07-28T12:00:39+01:00 | Claude | tag-added | Tag Attached: done-by-claude | | 2026-07-28T12:00:41+01:00 | Claude | note-added | Note Added: 0000074 | | 2026-07-28T12:00:45+01:00 | Claude | Status | new => resolved | ---- Synced automatically from MantisBT issue #115.