# Manual Deployment Instructions - Record Payment Button Fix

## Problem
The "Record Payment" button is missing from **both**:
1. ❌ Loan detail page (loan 18112026-000012)
2. ❌ Loans list page (for rolled-over loans)

## Root Cause
Both templates only checked `status == 'active' or status == 'rolled_over'`, but they didn't check the `is_rolled_over` boolean flag.

Looking at the loan detail page you showed:
- Shows "🔄 RENEWED" badge
- Has all loan details
- Missing "Record Payment" button
- This means `is_rolled_over = True` but the status field might not be in ('active', 'rolled_over')

## Solution - Update TWO Files

### File 1: `templates/loans/loan_detail.html`

Find this section (around line 72):
```django
{% if loan.status == 'active' or loan.status == 'rolled_over' %}
<!-- Payment Actions -->
<button onclick="showRepaymentModal('{{ loan.pk }}')" class="rounded-md bg-primary px-3 py-2 text-center text-sm font-semibold text-white shadow-sm hover:bg-secondary">
    Record Payment
</button>
{% if loan.status == 'active' %}
<button onclick="showRolloverModal('{{ loan.pk }}')" class="rounded-md bg-white px-3 py-2 text-center text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50">
    Request Rollover
</button>
{% endif %}
{% endif %}
```

**Replace with:**
```django
{% if loan.status == 'active' or loan.status == 'rolled_over' or loan.is_rolled_over %}
<!-- Payment Actions -->
<button onclick="showRepaymentModal('{{ loan.pk }}')" class="rounded-md bg-primary px-3 py-2 text-center text-sm font-semibold text-white shadow-sm hover:bg-secondary">
    Record Payment
</button>
{% if loan.status == 'active' and not loan.is_rolled_over %}
<button onclick="showRolloverModal('{{ loan.pk }}')" class="rounded-md bg-white px-3 py-2 text-center text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50">
    Request Rollover
</button>
{% endif %}
{% endif %}
```

### File 2: `templates/loans/loans_table.html`

Find this section (around line 211):
```django
{% if application.loan.status == 'active' %}
<!-- Record Payment -->
<button onclick="showRepaymentModal('{{ application.loan.pk }}')"
        class="text-green-600 hover:text-green-800 transition-colors duration-150"
        title="Record Payment">
    <span>💵</span>
</button>

<!-- Request Rollover -->
<button onclick="showRolloverModal(
            '{{ application.loan.pk }}',
            {{ application.loan.outstanding_amount|default:0 }},
            {{ application.loan_product.interest_rate|default:0 }},
            {{ application.loan_product.rollover_fee_percentage|default:0 }}
        )"
        class="text-blue-600 hover:text-blue-800 transition-colors duration-150"
        title="Request Rollover">
    <span>↷</span>
</button>
{% endif %}
```

**Replace with:**
```django
{% if application.loan.status == 'active' or application.loan.status == 'rolled_over' or application.loan.is_rolled_over %}
<!-- Record Payment -->
<button onclick="showRepaymentModal('{{ application.loan.pk }}')"
        class="text-green-600 hover:text-green-800 transition-colors duration-150"
        title="Record Payment">
    <span>💵</span>
</button>
{% endif %}

{% if application.loan.status == 'active' and not application.loan.is_rolled_over %}
<!-- Request Rollover (only for non-rolled active loans) -->
<button onclick="showRolloverModal(
            '{{ application.loan.pk }}',
            {{ application.loan.outstanding_amount|default:0 }},
            {{ application.loan_product.interest_rate|default:0 }},
            {{ application.loan_product.rollover_fee_percentage|default:0 }}
        )"
        class="text-blue-600 hover:text-blue-800 transition-colors duration-150"
        title="Request Rollover">
    <span>↷</span>
</button>
{% endif %}
```

## Changes Summary

### What Changed:
1. **Record Payment Button** now shows when ANY of:
   - `status == 'active'` 
   - `status == 'rolled_over'`
   - `is_rolled_over == True` ⬅️ **THIS IS THE KEY FIX**

2. **Request Rollover Button** now only shows when:
   - `status == 'active'` AND
   - `is_rolled_over == False` (not already rolled)

### Why This Works:
The loan 18112026-000012 has:
- `is_rolled_over = True` (shows "🔄 RENEWED" badge)
- But the `status` field might be something other than 'active' or 'rolled_over'

By adding `or loan.is_rolled_over` to the condition, the button will show regardless of the status field value, as long as the loan is marked as rolled over.

## Deployment Steps

1. **Upload files via SFTP/FTP:**
   ```
   Local: c:\Users\BEST\Desktop\grazuri\templates\loans\loan_detail.html
   Remote: /home/xygbfpsg/loanapp.grazurifinance.co.ke/templates/loans/loan_detail.html
   
   Local: c:\Users\BEST\Desktop\grazuri\templates\loans\loans_table.html
   Remote: /home/xygbfpsg/loanapp.grazurifinance.co.ke/templates/loans/loans_table.html
   ```

2. **Restart the application:**
   ```bash
   cd /home/xygbfpsg/loanapp.grazurifinance.co.ke
   touch tmp/restart.txt
   ```

3. **Clear browser cache** (Ctrl+F5 or Cmd+Shift+R)

4. **Test:**
   - Navigate to loan 18112026-000012 detail page
   - ✅ Verify "Record Payment" button appears
   - ✅ Verify "Request Rollover" button does NOT appear (already rolled)
   - Navigate to loans list page
   - ✅ Verify all rolled loans show the 💵 button
   - ✅ Verify rolled loans don't show the ↷ button

## Files Ready to Upload
Both files have been updated locally at:
- `c:\Users\BEST\Desktop\grazuri\templates\loans\loan_detail.html` ✅
- `c:\Users\BEST\Desktop\grazuri\templates\loans\loans_table.html` ✅

Just upload these two files and restart the app!
