# Review of the Original Bank Reconciliation Module

## Critical findings

1. `deposit_recon.php` was completely empty.
2. `reconcile_deposits.php` contained a duplicated `LEFT JOIN deposit_reconciliations drl`, making the fallback auto-match SQL invalid.
3. The module assumed columns such as `statement_name`, while the historical error log showed those columns were missing in production.
4. The cheque reconciliation used legacy cheque fields in `payments` and did not properly integrate with the newer `payment_cheques` and `payment_cheque_allocations` model.
5. Clearing cheques directly changed statuses but did not consistently convert planned allocations into effective invoice allocations or recalculate invoice balances.
6. The importer recognized only one exact CSV header structure and used `strtotime()` for dates such as `01.07.2026`, which can be interpreted inconsistently.
7. Duplicate detection was line-based but lacked exact-file protection, so the same statement could be imported repeatedly.
8. Automatic matching was mostly exact reference/amount matching and did not provide confidence scoring or date/party-name support.
9. Deposit reconciliation identified bank lines using reference + date + amount because the old reconciliation table had no direct bank-line key, creating collision risk.
10. Debug error display was enabled in production-facing files.
11. SMS API credentials, allowed phone numbers, and OTP configuration were embedded directly in the public PHP source.
12. The SMS sender considered any HTTP 2xx response successful, even though the supplied log showed provider-level rejection with `MessageErrorCode: 403` and zero balance.
13. The old module had inconsistent login routes and session checks (`username`, `user_id`, `/login.php`, and `/auth/login.php`).
14. The error log contained repeated PHP null/deprecation warnings and historical schema failures.

## Improvements delivered

- Safe schema installer compatible with older MySQL versions.
- New normalized match table linked directly to bank statement line IDs.
- Flexible statement parser and transaction classifier.
- File-level and line-level duplicate controls.
- High-confidence unique automatic matching.
- Human review and controlled confirmation.
- Integration with the advanced cheque/payment allocation flow.
- Reconciliation summary, balance control, exception register, audit trail, and CSV export.
- Responsive dashboard and workspaces.
- No hard-coded SMS secrets or phone numbers.
