# Fix Loan Total Amount Calculation Issue

## Problem
The loan LOAN-000193 is showing an incorrect total amount of KES 29,344.00 instead of the correct KES 35,370.00.

**Breakdown:**
- Principal: KES 26,200.00
- Interest: KES 7,860.00
- Processing Fee: KES 1,310.00
- **Correct Total: KES 35,370.00** (26,200 + 7,860 + 1,310)
- **Current (Wrong) Total: KES 29,344.00**

## Root Cause
The `total_amount` field in the database is stored incorrectly. The correct formula is:
```
total_amount = principal_amount + interest_amount + processing_fee
```

## Solutions

### Option 1: Run Django Management Command
```bash
python manage.py fix_loan_totals
```

This will:
- Check all loans in the database
- Identify loans with incorrect total_amount
- Fix them automatically
- Show a detailed report

### Option 2: Run SQL Script Directly
Connect to your MySQL database and run:

```sql
-- Check which loans have incorrect totals
SELECT 
    loan_number,
    principal_amount,
    interest_amount,
    processing_fee,
    total_amount as current_total,
    (principal_amount + interest_amount + processing_fee) as correct_total,
    (principal_amount + interest_amount + processing_fee - total_amount) as difference
FROM loans
WHERE total_amount != (principal_amount + interest_amount + processing_fee);

-- Fix all loans with incorrect totals
UPDATE loans
SET total_amount = principal_amount + interest_amount + processing_fee
WHERE total_amount != (principal_amount + interest_amount + processing_fee);

-- Verify the specific loan
SELECT 
    loan_number,
    principal_amount,
    interest_amount,
    processing_fee,
    total