# Amount Paid Field Error Fix

## Issue
The portfolio manager detail view was throwing a `FieldError`:
```
Cannot resolve keyword 'amount_paid' into field. Choices are: _amount_paid_cache, application, application_id, borrower, ...
```

## Root Cause
The `amount_paid` field on the `Loan` model is a **property** (calculated dynamically from repayments), not a database field. Properties cannot be used in database queries like:
- `Sum('amount_paid')`
- `filter(amount_paid__gt=...)`
- `order_by('amount_paid')`

The actual database field is `_amount_paid_cache` which stores a cached value of the amount paid.

## Solution
Replaced all occurrences of `amount_paid` in database aggregations with `_amount_paid_cache`:

### Files Fixed:
1. **users/services.py** (multiple occurrences)
   - Line 2447-2449: Loan metrics aggregation
   - Line 2456: Period-specific loan metrics
   - Line 2716: Client loan statistics
   - Line 2802-2828: Portfolio at Risk calculations
   - Line 2884-2896: PAR calculations
   - Line 2909: Client outstanding calculations
   - Line 3060-3068: Concentration risk analysis

2. **check_dashboard_data.py**
   - Line 40: Active loan data aggregation

3. **add_overdue_completed_reports.py**
   - Line 153: Completed loans repayment calculation

4. **add_missing_views.py**
   - Line 63: Total collected calculation

## Changes Made
```python
# Before (WRONG - causes FieldError)
Sum('amount_paid')

# After (CORRECT - uses cached field)
Sum('_amount_paid_cache')
```

## Why This Works
- `_amount_paid_cache` is a real database field (DecimalField) that stores the cached amount paid
- The `amount_paid` property uses `LoanCalculationService` to calculate the value dynamically
- For database queries and aggregations, we must use the cached field
- For individual loan access (e.g., `loan.amount_paid`), the property works fine

## Testing
Run Django check to verify no errors:
```bash
python manage.py check
```

## Impact
This fix resolves the error on the portfolio manager detail page:
- URL: `/portfolio/manager/{manager_id}/`
- View: `users.portfolio_views.portfolio_manager_detail`

The page should now load correctly without FieldError exceptions.
