mfraz commited on
Commit
b23bc0e
·
verified ·
1 Parent(s): 7e6d12d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -4
app.py CHANGED
@@ -120,10 +120,23 @@ def generate_balance_sheet(ledger_df, net_income):
120
  equity = net_income # Retained earnings
121
 
122
  for index, row in ledger_df.iterrows():
123
- if row["Balance"] > 0:
124
- assets += row["Balance"]
125
- elif row["Balance"] < 0:
126
- liabilities += abs(row["Balance"])
 
 
 
 
 
 
 
 
 
 
 
 
 
127
 
128
  balance_sheet = pd.DataFrame({
129
  "Category": ["Total Assets", "Total Liabilities", "Total Equity"],
 
120
  equity = net_income # Retained earnings
121
 
122
  for index, row in ledger_df.iterrows():
123
+ account_name = row["Account"]
124
+ balance = row["Balance"]
125
+
126
+ if any(keyword in account_name.lower() for keyword in ["cash", "inventory", "equipment", "accounts receivable"]):
127
+ assets += balance
128
+ elif any(keyword in account_name.lower() for keyword in ["loan", "accounts payable"]):
129
+ liabilities += abs(balance)
130
+ elif any(keyword in account_name.lower() for keyword in ["capital", "equity"]):
131
+ equity += balance
132
+
133
+ # Ensuring the balance equation holds: Assets = Liabilities + Equity
134
+ if assets != (liabilities + equity):
135
+ difference = assets - (liabilities + equity)
136
+ if difference > 0:
137
+ liabilities += difference
138
+ else:
139
+ assets += abs(difference)
140
 
141
  balance_sheet = pd.DataFrame({
142
  "Category": ["Total Assets", "Total Liabilities", "Total Equity"],