# Allocation Audit & Export Update

## Summary
Added an allocation audit report page with filter controls, plus export support for Excel and PDF.

## What changed
- Added new admin report route: `reports/allocations`
- Added `Allocation Audit Report` button on the admin reports landing page
- Added filter controls for:
  - `start_date`
  - `end_date`
  - `loan_id`
  - `batch_reference`
- Added Excel and PDF export actions for allocation audit results
- Added PDF export sizing for A4 landscape and full-page width
- Added pagination and totals for allocation report results
- Documented the allocation audit structure and storage model

## Allocation audit structure
Payment allocation audits are persisted in `payment_allocations` with the following key fields:
- `loan_id`: the loan to which the allocation belongs
- `repayment_id`: the specific repayment installment the allocation was applied to
- `transaction_id`: the source payment or MPesa transaction reference
- `amount`: the amount allocated in this audit entry
- `balance_before`: the repayment balance before the allocation
- `balance_after`: the repayment balance after the allocation
- `batch_reference`: a grouping token for related allocations from the same callback or payment batch
- `created_at`: audit timestamp for traceability

This structure preserves the actual allocation sequence and enables admins to inspect how each payment was distributed across loan repayment items.

## Files changed
- `routes/web.php`
  - Added `admin.reports.allocations` page route
  - Added export route names for allocations exports
- `app/Http/Controllers/Admin/AdminReportingController.php`
  - Added `allocationReport()` method
  - Query filters allocations by loan, batch reference, and date range
  - Loads allocations with `loan.user` and `repayment` relations
- `resources/views/admin/reports/index.blade.php`
  - Added `Allocation Audit Report` button to the reports dashboard
- `resources/views/admin/reports/allocations.blade.php`
  - New allocations report view
  - Includes filter form, totals cards, table, and pagination

## Notes
- Allocation export buttons preserve current filter state via query string
- PDF export is configured for A4 landscape layout with width constrained to the page and automatic height
- This update supports audit traceability for payment allocations and helps admins review allocation batches and per-repayment adjustments
