# Deploy Client Performance Fix

## What Was Fixed

The client performance ranking page was showing zeros because:
1. Wrong database field names (`calculated_total_amount` vs `total_amount`)
2. Inefficient loop causing duplicates for admin users
3. Missing handling for clients without portfolio managers

## Files Changed

- `users/portfolio_views.py` - Fixed the `client_performance_ranking()` function

## How to Deploy

### Option 1: Upload via cPanel File Manager
1. Go to cPanel → File Manager
2. Navigate to `/public_html/branchbusinessadvance.co.ke/users/`
3. Upload the fixed `portfolio_views.py` file
4. Restart your application (if using Passenger, create/touch `tmp/restart.txt`)

### Option 2: Upload via FTP/SFTP
1. Connect to your server via FTP
2. Navigate to `/public_html/branchbusinessadvance.co.ke/users/`
3. Upload `portfolio_views.py`
4. Restart application

### Option 3: Via SSH/Terminal
```bash
cd ~/public_html/branchbusinessadvance.co.ke
# Upload the file, then:
touch tmp/restart.txt
```

## Verify the Fix

1. Log in as admin user
2. Go to Client Performance Ranking page
3. You should now see:
   - Total Clients: 73
   - Active portfolio data
   - Client scores and ratings
   - Repayment rates
   - Outstanding amounts
   - Top performers list

## Expected Results

Based on your production database:
- **Total Clients**: 73 active borrowers
- **Total Loans**: 110 (50 active)
- **Total Disbursed**: KES 2,958,038.52
- **Total Outstanding**: KES 1,627,433.83
- **Total Repaid**: KES 792,901.81

## Troubleshooting

If still showing zeros:
1. Clear browser cache
2. Check if file was uploaded correctly
3. Restart application: `touch tmp/restart.txt`
4. Check error logs in cPanel

## Test Script

Run this to verify the fix works:
```bash
python test_client_performance_view.py
```

Should show: "✅ Data collection works!"
