# SmartPay360 Advanced Bank Reconciliation

## Installation

1. Back up the database and the existing `modules/bank_recon` folder.
2. Replace that folder with the supplied `bank_recon` folder.
3. Log in to SmartPay360 and open `modules/bank_recon/install.php`.
4. Click **Install / Upgrade Database** once.
5. Open **Upload Statement**, select the bank account, and upload the CSV.

## Main upgrades

- Flexible CSV header recognition and delimiter detection.
- Exact-file duplicate prevention using SHA-256.
- Per-line duplicate and suspicious-transaction flags.
- Kenyan and ISO date parsing.
- Automatic classification: cheques, deposits, M-Pesa, transfers, charges, credits, debits, and opening balances.
- Cheque number extraction from descriptions such as `CHQ No. 004133`.
- Confidence scoring using amount, reference/cheque number, date proximity, and party name.
- Automatic matching only for unique high-confidence pairs.
- Manual review before confirmation.
- Confirmation updates `payment_cheques` and `payments`, copies planned cheque allocations into effective payment allocations, and recalculates invoices when the shared payments library is present.
- Deposit matching supports common `bank_deposits` column variations.
- Complete match register, exception register, CSV export, and audit trail.
- Mobile-responsive control-centre interface.
- Compatibility redirects for the old `reconcile_cheques.php`, `reconcile_deposits.php`, and `deposit_recon.php` URLs.

## Important security change

The old landing page contained live SMS credentials and approved phone numbers directly in PHP. They have intentionally not been copied into this version. Authentication now uses the existing SmartPay360 login session. Any future OTP implementation should load credentials from environment variables or a protected configuration outside the public web root.

## Uploaded statement test

The provided `transactionHistory (46).csv` was used to verify the parser design. It contains 434 rows covering July 1–27, 2026, including cheque lines, deposits, transfers, M-Pesa entries, charges, other debits/credits, and an opening-balance row.
