# Branch Filtering Production Deployment Checklist

## Pre-Deployment Checklist

### 1. Environment Preparation
- [ ] Backup current production database
- [ ] Backup current production code
- [ ] Verify production server access
- [ ] Check disk space and system resources
- [ ] Ensure maintenance window is scheduled

### 2. Code Deployment
- [ ] Deploy updated files to production server:
  - [ ] `loans/views.py` (completed_loans, deleted_loans branch filtering)
  - [ ] `reports/comprehensive_reports.py` (enhanced report methods)
  - [ ] `templates/utils/payment_receipts.html` (new template)
  - [ ] Test scripts for verification

### 3. Dependencies Check
- [ ] Verify Django version compatibility
- [ ] Check Python version compatibility
- [ ] Ensure all required packages are installed
- [ ] Verify database connection settings

## Deployment Steps

### Step 1: Deploy Code Changes
```bash
# 1. Navigate to production directory
cd /path/to/production/branch-system

# 2. Backup current code
cp -r . ../backup_$(date +%Y%m%d_%H%M%S)

# 3. Deploy new files
# Copy the modified files to production

# 4. Set proper permissions
chown -R www-data:www-data .
chmod -R 755 .
```

### Step 2: Run Deployment Verification
```bash
# Run the production deployment verification script
python production_branch_filtering_deployment.py
```

### Step 3: Restart Services
```bash
# Restart web server (adjust for your setup)
sudo systemctl restart apache2
# OR
sudo systemctl restart nginx
sudo systemctl restart gunicorn

# Clear Django cache if applicable
python manage.py clear_cache
```

### Step 4: Verify Functionality
- [ ] Test branch filtering on all pages
- [ ] Verify registration fees display correctly
- [ ] Check reports dashboard functionality
- [ ] Test user access and permissions
- [ ] Verify no errors in logs

## Post-Deployment Verification

### 1. Functional Testing
- [ ] Login as different user types (admin, staff, regular user)
- [ ] Test branch selection functionality
- [ ] Verify completed loans page filters by branch
- [ ] Verify deleted loans page filters by branch
- [ ] Test payment receipts page
- [ ] Test notifications page
- [ ] Test reports dashboard
- [ ] Verify registration fees show correct amounts

### 2. Performance Testing
- [ ] Check page load times
- [ ] Monitor database query performance
- [ ] Verify no memory leaks
- [ ] Check server resource usage

### 3. Error Monitoring
- [ ] Check Django error logs
- [ ] Monitor web server error logs
- [ ] Verify no 500 errors
- [ ] Check for any JavaScript errors

## Rollback Plan (If Issues Occur)

### Immediate Rollback Steps
```bash
# 1. Stop web services
sudo systemctl stop apache2  # or nginx/gunicorn

# 2. Restore previous code
cd /path/to/production
rm -rf branch-system
mv backup_YYYYMMDD_HHMMSS branch-system
cd branch-system

# 3. Restart services
sudo systemctl start apache2

# 4. Verify rollback successful
python production_branch_filtering_deployment.py
```

### Database Rollback (if needed)
```bash
# Only if database changes were made (none in this deployment)
# Restore database backup if necessary
```

## Success Criteria

### All Must Pass:
- [ ] ✅ Django setup successful
- [ ] ✅ Database connection working
- [ ] ✅ All views respond correctly
- [ ] ✅ Branch filtering works on all pages
- [ ] ✅ Registration fees show correct amounts
- [ ] ✅ No errors in logs
- [ ] ✅ Performance is acceptable
- [ ] ✅ All user roles can access appropriate data

## Contact Information

### Support Team
- **Primary Contact**: [Your Name/Team]
- **Phone**: [Emergency Contact]
- **Email**: [Support Email]

### Escalation
- **Technical Lead**: [Name/Contact]
- **System Administrator**: [Name/Contact]

## Deployment Log

### Deployment Details
- **Date**: _______________
- **Time**: _______________
- **Deployed By**: _______________
- **Version/Commit**: _______________

### Verification Results
- **Pre-deployment checks**: ✅ / ❌
- **Code deployment**: ✅ / ❌
- **Service restart**: ✅ / ❌
- **Functional testing**: ✅ / ❌
- **Performance testing**: ✅ / ❌

### Issues Encountered
```
[Document any issues and their resolutions]
```

### Sign-off
- **Technical Lead**: _________________ Date: _______
- **System Admin**: _________________ Date: _______
- **Business Owner**: _________________ Date: _______

---

## Quick Reference Commands

### Check System Status
```bash
# Check web server status
sudo systemctl status apache2

# Check Django application
python manage.py check

# Check database connectivity
python manage.py dbshell

# View recent logs
tail -f /var/log/apache2/error.log
tail -f /var/log/django/django.log
```

### Emergency Contacts
- **System Down**: [Emergency Number]
- **Data Issues**: [Data Team Contact]
- **User Access Issues**: [Support Team Contact]