"""
Check the specific loan LOAN-000105 to see its actual data
"""

import os
import django

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'branch_system.settings')
django.setup()

from loans.models import Loan

# Search for loan 105
loans = Loan.objects.filter(loan_number__icontains='105')

print("=" * 80)
print("SEARCHING FOR LOAN 105")
print("=" * 80)

if not loans.exists():
    print("\n❌ No loans found with '105' in the loan number")
else:
    print(f"\nFound {loans.count()} loan(s):")
    for loan in loans:
        print(f"\n{'-'*60}")
        print(f"Loan ID: {loan.pk}")
        print(f"Loan Number (raw): '{loan.loan_number}'")
        print(f"Loan Number (repr): {repr(loan.loan_number)}")
        print(f"Status: {loan.status}")
        print(f"is_deleted: {loan.is_deleted}")
        print(f"deleted_at: {loan.deleted_at}")
        print(f"deleted_by: {loan.deleted_by}")
        print(f"Borrower: {loan.borrower.get_full_name()}")
        print(f"Principal: KES {loan.principal_amount}")
        print(f"Total Amount: KES {loan.total_amount}")
        print(f"Disbursement Date: {loan.disbursement_date}")
        print(f"Due Date: {loan.due_date}")
        print(f"Product: {loan.application.loan_product.get_product_type_display()}")
        
        # Check if DELETED is in the loan number
        if 'DELETED' in loan.loan_number.upper():
            print(f"\n⚠️  WARNING: 'DELETED' found in loan_number field!")
            print(f"   This should not happen - the suffix should not be in the database")

print(f"\n{'='*80}")
