Table of Contents

#139 — add a delete tab specifically for the finance module only accessable to managers and admins (Resolved)

← Back to Manara Bugs · View issue #139 in MantisBT


Reported by: Khaled Tarabay on 2026-07-29T08:15:47+01:00
Assigned to: Claude
Resolved by: Claude on 2026-07-29T09:33:56+01:00
Severity: major
Priority: normal
Reproducibility: always
Category: General

Description: what I mean is that there must be an option to delete entries and stuff from the finance module but it only super admins should be allowed to hard delete and delete permanently yet it must show in the activity log, and managers should be able to soft delete and other roles shouldn't be able to see the delete button or the new “Deleted Transactions” tab of the finance module in which everything that is deleted in the finance module shows up there.

Resolution: FIXED — the finance module now has its own “Deleted Transactions” trash, role-gated exactly as requested.

WHAT: - A new “Deleted Transactions” tab (/finance/deleted) that lists everything soft-deleted across the finance module (Expenses, Reconciliation sessions, Radius entries, Refunds & Credits) — newest first. - A MANAGER or ADMIN can soft-delete a finance entry (it moves to the trash) and RESTORE it from the trash. - Only the OWNER (super_admin) sees/uses the “Delete permanently” (hard-delete) button. - Every soft-delete, restore, and permanent-delete is written to the Activity Log. - No other role sees the tab, the delete buttons, or any of these actions (the delete button is hidden AND a direct POST is blocked server-side).

WHERE / FIX: - Migration 070: deleted_at added to transactions, credit_notes, reconciliation_sessions, radius_entries; all four models set =true and every read query filters deleted_at IS NULL (including the cross-module aggregates in Invoice/Payment/Report that feed Business Overview, so a trashed finance row never leaks into a dashboard total). reconciliation_sessions/radius_entries had a plain one-per-day UNIQUE that would let a trashed row keep blocking a new same-date entry, so those were swapped to the generated “_active” unique pattern already used by tenants/customers/invoices (NULL once deleted). - New FinanceRecycleController (index/restore/forceDelete) — NoPermissionRequired + role checks: view+restore require manager|admin, forceDelete requires super_admin. Restore re-checks a date conflict so restoring a session/entry whose date was reused while binned fails with a friendly message instead of a duplicate-key crash. Static canSoftDelete() (admin|manager) shared by the reconciliation/radius controllers AND their views to hide the Delete button + block direct POSTs. New finance/deleted.php view; routes; sidebar “Deleted Transactions” entry (new adminOrManager gate flag) + a toolbar link on the Expenses page.

SCOPE NOTES: Money records (invoices/payments/wallet/commissions) stay void-not-delete by the app's accounting design and are NOT in this trash. Expenses keep their existing stricter rule (admin any time, manager only same-day — from #125), which is a subset of “managers can soft-delete”. Refunds & Credits (credit_notes) are registered in the trash so anything soft-deleted there is visible/restorable, but they keep no user-facing delete trigger (immutable financial record by design, like payments/invoices).

VERIFIED LIVE (28/28) against the local DB across the full role matrix (super_admin / manager / finance-role / field_officer): soft-delete→trash→restore round-trip for radius/reconciliation/expenses; the unique-constraint fix (a new session for the same date while the old is trashed); restore-conflict handling; owner-only permanent delete; and that a role holding reconciliation.run+payments.record but NOT manager/admin is redirected from the tab, sees no Delete button/link, and is blocked on a direct POST. PHPUnit 29/29.

Prod: run /run-migrations.php for migration 070.

Activity / Notes

WHAT: - A new “Deleted Transactions” tab (/finance/deleted) that lists everything soft-deleted across the finance module (Expenses, Reconciliation sessions, Radius entries, Refunds & Credits) — newest first. - A MANAGER or ADMIN can soft-delete a finance entry (it moves to the trash) and RESTORE it from the trash. - Only the OWNER (super_admin) sees/uses the “Delete permanently” (hard-delete) button. - Every soft-delete, restore, and permanent-delete is written to the Activity Log. - No other role sees the tab, the delete buttons, or any of these actions (the delete button is hidden AND a direct POST is blocked server-side).

WHERE / FIX: - Migration 070: deleted_at added to transactions, credit_notes, reconciliation_sessions, radius_entries; all four models set =true and every read query filters deleted_at IS NULL (including the cross-module aggregates in Invoice/Payment/Report that feed Business Overview, so a trashed finance row never leaks into a dashboard total). reconciliation_sessions/radius_entries had a plain one-per-day UNIQUE that would let a trashed row keep blocking a new same-date entry, so those were swapped to the generated “_active” unique pattern already used by tenants/customers/invoices (NULL once deleted). - New FinanceRecycleController (index/restore/forceDelete) — NoPermissionRequired + role checks: view+restore require manager|admin, forceDelete requires super_admin. Restore re-checks a date conflict so restoring a session/entry whose date was reused while binned fails with a friendly message instead of a duplicate-key crash. Static canSoftDelete() (admin|manager) shared by the reconciliation/radius controllers AND their views to hide the Delete button + block direct POSTs. New finance/deleted.php view; routes; sidebar “Deleted Transactions” entry (new adminOrManager gate flag) + a toolbar link on the Expenses page.

SCOPE NOTES: Money records (invoices/payments/wallet/commissions) stay void-not-delete by the app's accounting design and are NOT in this trash. Expenses keep their existing stricter rule (admin any time, manager only same-day — from #125), which is a subset of “managers can soft-delete”. Refunds & Credits (credit_notes) are registered in the trash so anything soft-deleted there is visible/restorable, but they keep no user-facing delete trigger (immutable financial record by design, like payments/invoices).

VERIFIED LIVE (28/28) against the local DB across the full role matrix (super_admin / manager / finance-role / field_officer): soft-delete→trash→restore round-trip for radius/reconciliation/expenses; the unique-constraint fix (a new session for the same date while the old is trashed); restore-conflict handling; owner-only permanent delete; and that a role holding reconciliation.run+payments.record but NOT manager/admin is redirected from the tab, sees no Delete button/link, and is blocked on a direct POST. PHPUnit 29/29.

Prod: run /run-migrations.php for migration 070.

Full History

Date User Field Change
2026-07-29T08:15:47+01:00 Khaled Tarabay issue-new New Issue
2026-07-29T09:33:50+01:00 Claude Assigned To ⇒ Claudine
2026-07-29T09:33:52+01:00 Claude tag-added Tag Attached: done-by-claude
2026-07-29T09:33:54+01:00 Claude note-added Note Added: 0000098
2026-07-29T09:33:56+01:00 Claude Status new ⇒ resolved

Synced automatically from MantisBT issue #139.