from accounting.models import *
from accounting.services.report_service import ReportService
from accounting.services.accounting_service import AccountingService
from datetime import date
from django.contrib.auth import get_user_model

User = get_user_model()

# Get any user for testing
user = User.objects.first()

# Get trial balance
rs = ReportService()
as_svc = AccountingService()

print("=== LEDGER ENTRIES ===")
for entry in GeneralLedger.objects.all().order_by('transaction_date', 'account__code'):
    print(f"{entry.transaction_date} {entry.account.code} {entry.account.name}: DR {entry.debit_amount}, CR {entry.credit_amount}, Balance: {entry.balance}")

print("\n=== TRIAL BALANCE ===")
tb = rs.generate_trial_balance(date(2024, 1, 31))
print('Total Debits:', tb['totals']['total_debits'])
print('Total Credits:', tb['totals']['total_credits'])
print('Balanced:', tb['totals']['balanced'])
print('\nAccounts:')
for acc in tb['accounts']:
    print(f"{acc['code']} {acc['name']}: DR {acc['debit_balance']}, CR {acc['credit_balance']}")
