====== #55 โ€” A finalized, Closed reconciliation session can be permanently deleted (Resolved) ====== [[wiki:manara:bugs|โ† Back to Manara Bugs]] ยท [[https://mantis.matrixdn.net/view.php?id=55|View issue #55 in MantisBT]] ---- **Reported by:** Khaled Tarabay on 2026-07-27T08:16:43+01:00\\ **Assigned to:** Claude\\ **Resolved by:** Claude on 2026-07-27T08:36:38+01:00\\ **Severity:** major\\ **Priority:** high\\ **Reproducibility:** always\\ **Category:** General **Description:** Once an end-of-day reconciliation session is Closed (finalized, with its discrepancy totals locked in), the app still lets it be deleted outright including all of its lines via a Delete button that is present and enabled specifically because the session is Closed, with a confirm dialog reading "This cannot be undone." Created a session, added a line producing a real $25.00 discrepancy, and Closed it. The session's own Delete action (POST /reconciliation/{id}/delete) was called and succeeded (302); a follow-up GET on the session returned 404 it is genuinely, permanently gone. This directly contradicts the immutable-once-finalized pattern enforced everywhere else in Finance: Payments, Refunds & Credits, and Commissions all explicitly block editing or deleting a finalized record specifically "for the audit trail." Reconciliation is the one module in this audit where a closed, finalized financial record can simply be erased โ€” and the seed data already contained a real example of this risk materializing (a Closed session dated Jan 1, 2030 with a genuine -$50.00 discrepancy, sitting exposed to the same Delete button). **Steps to Reproduce:** Go to /reconciliation, click "+ Open Session," pick any business date. Add at least one line with a System Amount different from the Manual Amount (to produce a real discrepancy). Click "Close Session." On the now-Closed session, click "Delete" and confirm. The session disappears from /reconciliation entirely; visiting its URL directly returns 404 the finalized discrepancy record is gone with no trace. **Resolution:** FIXED. What: once a reconciliation session was Closed (finalized, discrepancy totals locked in), it could still be permanently deleted via its own Delete button -- which was present and enabled specifically because the session was Closed. This contradicted the immutable-once-finalized rule Payments/Refunds & Credits/Commissions already enforce. Where: app/classes/Finance/ReconciliationSession.php (new delete() override), app/views/reconciliation/show.php + app/views/reconciliation/index.php (Delete button now hidden once closed). Why: no guard existed anywhere -- the model had no delete() override at all, so it fell through to the base Model::delete(), which has no concept of "finalized." A closed session's discrepancy totals ARE the audit record; erasing it destroys that record with no trace, exactly like deleting a Payment would. Fix: ReconciliationSession::delete() now throws the same typed RestrictedDeleteException the rest of the app already uses for a blocked delete, whenever the session's status is 'closed' -- the Router already turns that into a friendly flash + redirect (or a 409 for /api/*) with zero controller changes needed. An OPEN session (opened by mistake, or never followed through) can still be deleted freely -- only closing makes it immutable. Both places with a Delete button (the session's own page and the sessions list) now hide it once closed, as the first line of defense; the model-level guard is what actually enforces it even against a direct POST bypassing the UI. Verified live against the local database: closed a session with a real $100 discrepancy line, confirmed the Delete button disappeared from both the session page and the list page, then POSTed directly to /reconciliation/{id}/delete anyway (bypassing the UI) -- correctly blocked with the flash "This reconciliation session is closed and finalized -- it can no longer be deleted," and the session was confirmed still present afterward. A second, OPEN session was then deleted normally to confirm no regression (302 to the list, followed by a 404 on its own page, confirming it was genuinely removed). Full test suite: 29/29 passing. ===== Activity / Notes ===== * **2026-07-27T08:36:35+01:00 - Claude:** FIXED. What: once a reconciliation session was Closed (finalized, discrepancy totals locked in), it could still be permanently deleted via its own Delete button -- which was present and enabled specifically because the session was Closed. This contradicted the immutable-once-finalized rule Payments/Refunds & Credits/Commissions already enforce. Where: app/classes/Finance/ReconciliationSession.php (new delete() override), app/views/reconciliation/show.php + app/views/reconciliation/index.php (Delete button now hidden once closed). Why: no guard existed anywhere -- the model had no delete() override at all, so it fell through to the base Model::delete(), which has no concept of "finalized." A closed session's discrepancy totals ARE the audit record; erasing it destroys that record with no trace, exactly like deleting a Payment would. Fix: ReconciliationSession::delete() now throws the same typed RestrictedDeleteException the rest of the app already uses for a blocked delete, whenever the session's status is 'closed' -- the Router already turns that into a friendly flash + redirect (or a 409 for /api/*) with zero controller changes needed. An OPEN session (opened by mistake, or never followed through) can still be deleted freely -- only closing makes it immutable. Both places with a Delete button (the session's own page and the sessions list) now hide it once closed, as the first line of defense; the model-level guard is what actually enforces it even against a direct POST bypassing the UI. Verified live against the local database: closed a session with a real $100 discrepancy line, confirmed the Delete button disappeared from both the session page and the list page, then POSTed directly to /reconciliation/{id}/delete anyway (bypassing the UI) -- correctly blocked with the flash "This reconciliation session is closed and finalized -- it can no longer be deleted," and the session was confirmed still present afterward. A second, OPEN session was then deleted normally to confirm no regression (302 to the list, followed by a 404 on its own page, confirming it was genuinely removed). Full test suite: 29/29 passing. ===== Full History ===== ^ Date ^ User ^ Field ^ Change ^ | 2026-07-27T08:16:43+01:00 | Khaled Tarabay | issue-new | New Issue | | 2026-07-27T08:36:31+01:00 | Claude | Assigned To | => Claudine | | 2026-07-27T08:36:34+01:00 | Claude | tag-added | Tag Attached: done-by-claude | | 2026-07-27T08:36:35+01:00 | Claude | note-added | Note Added: 0000014 | | 2026-07-27T08:36:38+01:00 | Claude | Status | new => resolved | ---- Synced automatically from MantisBT issue #55.