Spaces:
Build error
Build error
File size: 1,635 Bytes
f6f7ab7 bbbebec f6f7ab7 bbbebec f6f7ab7 bbbebec f6f7ab7 bbbebec f6f7ab7 bbbebec | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | import pandas as pd
from models import Transaction
def transactions_to_dataframe(transactions):
"""Convert transactions to pandas DataFrame"""
data = []
for t in transactions:
data.append({
'Date': t.date,
'Description': t.description,
'Amount': f"${t.amount:.2f}",
'Type': t.transaction_type,
'Category': t.category
})
return pd.DataFrame(data)
def calculate_totals(transactions):
"""Calculate total credits and debits"""
total_credits = sum(t.amount for t in transactions if t.transaction_type == 'credit')
total_debits = sum(t.amount for t in transactions if t.transaction_type == 'debit')
net_amount = total_credits - total_debits
return {
'total_credits': total_credits,
'total_debits': total_debits,
'net_amount': net_amount
}
def generate_statement_report(statement_data):
"""Generate a text report from statement data"""
report = []
report.append(f"Bank: {statement_data.get('bank_name', 'Unknown')}")
report.append(f"Account: {statement_data.get('account_number', 'Unknown')}")
report.append("")
transactions = [Transaction(**t) for t in statement_data.get('transactions', [])]
totals = calculate_totals(transactions)
report.append(f"Total Credits: ${totals['total_credits']:.2f}")
report.append(f"Total Debits: ${totals['total_debits']:.2f}")
report.append(f"Net Amount: ${totals['net_amount']:.2f}")
report.append("")
report.append(f"Number of Transactions: {len(transactions)}")
return "\n".join(report) |