AI agent that generates P&L statement from trial balance revenue, cost, expenses, net profit calculation.
import sqlite3, json
DB_PATH = "finance.db"
def fetch_trial_balance(month):
conn = sqlite3.connect(DB_PATH)
cur = conn.cursor()
cur.execute("SELECT account, amount FROM trial_balance WHERE month=?", (month,))
return {r[0]: r[1] for r in cur.fetchall()}
def classify_pnl(accounts):
revenue = sum(v for k,v in accounts.items() if k.startswith('REV'))
cogs = sum(v for k,v in accounts.items() if k.startswith('COGS'))
expenses = sum(v for k,v in accounts.items() if k.startswith('EXP'))
gross = revenue - cogs
net = gross - expenses
return {"Revenue": revenue, "COGS": cogs, "Gross Profit": gross, "Expenses": expenses, "Net Profit": net}
def calculate_variance(current, previous):
return {k: round((v - previous.get(k,0))/previous.get(k,1)*100, 1) for k,v in current.items()}
pl = classify_pnl(fetch_trial_balance("2026-06"))
prev = classify_pnl(fetch_trial_balance("2026-05"))
variance = calculate_variance(pl, prev)
print(json.dumps({"pl": pl, "variance": variance}))
Basic Package
Special SME traction programme by AINNA.
Limited starter website offer. AI usage, hosting, maintenance and custom integrations depend on the confirmed scope.
View SME Offer โ
Ask about AINNA pages, services and articles.
AINNA sources only ยท up to 5 lines ยท 20 questions/hour
No section data available yet.
Sites with documented sections will appear here.
We value your privacy
We use browser storage to remember your choice. Optional analytics runs only after you allow it; your choice is recorded with an anonymous ID. Privacy Policy