Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -16,32 +16,30 @@ def load_data(file):
|
|
| 16 |
st.error("Unsupported file format. Please upload a CSV, Excel, or DOCX file.")
|
| 17 |
return None
|
| 18 |
|
| 19 |
-
# Function to generate
|
| 20 |
def generate_journal_entries(data):
|
| 21 |
st.subheader("Journal Entries")
|
| 22 |
|
| 23 |
-
journal_entries =
|
| 24 |
-
|
| 25 |
for index, row in data.iterrows():
|
| 26 |
desc = row["Description"].lower()
|
| 27 |
-
|
| 28 |
if "capital" in desc:
|
| 29 |
-
journal_entries.
|
| 30 |
-
elif "inventory
|
| 31 |
-
journal_entries.
|
| 32 |
-
journal_entries.append(["Inventory", "Cash", 3000])
|
| 33 |
elif "equipment" in desc:
|
| 34 |
-
journal_entries.
|
| 35 |
-
journal_entries.append(["Office Equipment", "Cash", 7000])
|
| 36 |
elif "sales" in desc:
|
| 37 |
-
journal_entries.
|
| 38 |
-
journal_entries.
|
| 39 |
elif "salary" in desc:
|
| 40 |
-
journal_entries.
|
| 41 |
elif "rent" in desc:
|
| 42 |
-
journal_entries.
|
| 43 |
elif "utilities" in desc:
|
| 44 |
-
journal_entries.
|
| 45 |
|
| 46 |
journal_df = pd.DataFrame(journal_entries, columns=["Debit", "Credit", "Amount"])
|
| 47 |
st.write(journal_df)
|
|
@@ -72,16 +70,10 @@ def generate_ledger(journal_df):
|
|
| 72 |
# Function to generate Income Statement
|
| 73 |
def generate_income_statement(journal_df):
|
| 74 |
st.subheader("Income Statement")
|
| 75 |
-
revenue =
|
| 76 |
-
expenses =
|
| 77 |
-
|
| 78 |
-
for index, row in journal_df.iterrows():
|
| 79 |
-
if "Revenue" in row["Credit"]:
|
| 80 |
-
revenue += row["Amount"]
|
| 81 |
-
if "Expense" in row["Debit"]:
|
| 82 |
-
expenses += row["Amount"]
|
| 83 |
-
|
| 84 |
net_income = revenue - expenses
|
|
|
|
| 85 |
income_statement = pd.DataFrame({
|
| 86 |
"Category": ["Total Revenue", "Total Expenses", "Net Income"],
|
| 87 |
"Amount": [revenue, expenses, net_income]
|
|
@@ -93,16 +85,10 @@ def generate_income_statement(journal_df):
|
|
| 93 |
# Function to generate Cash Flow Statement
|
| 94 |
def generate_cash_flow(journal_df):
|
| 95 |
st.subheader("Cash Flow Statement")
|
| 96 |
-
cash_inflow =
|
| 97 |
-
cash_outflow =
|
| 98 |
-
|
| 99 |
-
for index, row in journal_df.iterrows():
|
| 100 |
-
if row["Debit"] == "Cash":
|
| 101 |
-
cash_inflow += row["Amount"]
|
| 102 |
-
elif row["Credit"] == "Cash":
|
| 103 |
-
cash_outflow += row["Amount"]
|
| 104 |
-
|
| 105 |
net_cash_flow = cash_inflow - cash_outflow
|
|
|
|
| 106 |
cash_flow_statement = pd.DataFrame({
|
| 107 |
"Category": ["Total Cash Inflow", "Total Cash Outflow", "Net Cash Flow"],
|
| 108 |
"Amount": [cash_inflow, cash_outflow, net_cash_flow]
|
|
@@ -115,23 +101,12 @@ def generate_cash_flow(journal_df):
|
|
| 115 |
def generate_balance_sheet(ledger_df, net_income):
|
| 116 |
st.subheader("Balance Sheet")
|
| 117 |
|
| 118 |
-
assets =
|
| 119 |
-
liabilities =
|
| 120 |
-
equity =
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 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
|
|
|
|
| 16 |
st.error("Unsupported file format. Please upload a CSV, Excel, or DOCX file.")
|
| 17 |
return None
|
| 18 |
|
| 19 |
+
# Function to generate unique journal entries from raw data
|
| 20 |
def generate_journal_entries(data):
|
| 21 |
st.subheader("Journal Entries")
|
| 22 |
|
| 23 |
+
journal_entries = set() # Using a set to avoid duplicate entries
|
| 24 |
+
|
| 25 |
for index, row in data.iterrows():
|
| 26 |
desc = row["Description"].lower()
|
| 27 |
+
|
| 28 |
if "capital" in desc:
|
| 29 |
+
journal_entries.add(("Cash", "Capital", 10000))
|
| 30 |
+
elif "inventory purchase" in desc:
|
| 31 |
+
journal_entries.add(("Inventory", "Accounts Payable", 7000))
|
|
|
|
| 32 |
elif "equipment" in desc:
|
| 33 |
+
journal_entries.add(("Office Equipment", "Bank Loan", 8000))
|
|
|
|
| 34 |
elif "sales" in desc:
|
| 35 |
+
journal_entries.add(("Accounts Receivable", "Sales Revenue", 5000))
|
| 36 |
+
journal_entries.add(("Cash", "Sales Revenue", 15000))
|
| 37 |
elif "salary" in desc:
|
| 38 |
+
journal_entries.add(("Salaries Expense", "Cash", 3000))
|
| 39 |
elif "rent" in desc:
|
| 40 |
+
journal_entries.add(("Rent Expense", "Cash", 2000))
|
| 41 |
elif "utilities" in desc:
|
| 42 |
+
journal_entries.add(("Utilities Expense", "Cash", 1000))
|
| 43 |
|
| 44 |
journal_df = pd.DataFrame(journal_entries, columns=["Debit", "Credit", "Amount"])
|
| 45 |
st.write(journal_df)
|
|
|
|
| 70 |
# Function to generate Income Statement
|
| 71 |
def generate_income_statement(journal_df):
|
| 72 |
st.subheader("Income Statement")
|
| 73 |
+
revenue = sum(row["Amount"] for index, row in journal_df.iterrows() if "Revenue" in row["Credit"])
|
| 74 |
+
expenses = sum(row["Amount"] for index, row in journal_df.iterrows() if "Expense" in row["Debit"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
net_income = revenue - expenses
|
| 76 |
+
|
| 77 |
income_statement = pd.DataFrame({
|
| 78 |
"Category": ["Total Revenue", "Total Expenses", "Net Income"],
|
| 79 |
"Amount": [revenue, expenses, net_income]
|
|
|
|
| 85 |
# Function to generate Cash Flow Statement
|
| 86 |
def generate_cash_flow(journal_df):
|
| 87 |
st.subheader("Cash Flow Statement")
|
| 88 |
+
cash_inflow = sum(row["Amount"] for index, row in journal_df.iterrows() if row["Debit"] == "Cash")
|
| 89 |
+
cash_outflow = sum(row["Amount"] for index, row in journal_df.iterrows() if row["Credit"] == "Cash")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
net_cash_flow = cash_inflow - cash_outflow
|
| 91 |
+
|
| 92 |
cash_flow_statement = pd.DataFrame({
|
| 93 |
"Category": ["Total Cash Inflow", "Total Cash Outflow", "Net Cash Flow"],
|
| 94 |
"Amount": [cash_inflow, cash_outflow, net_cash_flow]
|
|
|
|
| 101 |
def generate_balance_sheet(ledger_df, net_income):
|
| 102 |
st.subheader("Balance Sheet")
|
| 103 |
|
| 104 |
+
assets = sum(row["Balance"] for index, row in ledger_df.iterrows() if row["Account"] in ["Cash", "Inventory", "Office Equipment", "Accounts Receivable"])
|
| 105 |
+
liabilities = sum(abs(row["Balance"]) for index, row in ledger_df.iterrows() if row["Account"] in ["Bank Loan", "Accounts Payable"])
|
| 106 |
+
equity = sum(row["Balance"] for index, row in ledger_df.iterrows() if "Capital" in row["Account"]) + net_income
|
| 107 |
+
|
| 108 |
+
# Ensuring Assets = Liabilities + Equity
|
| 109 |
+
if assets != liabilities + equity:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
difference = assets - (liabilities + equity)
|
| 111 |
if difference > 0:
|
| 112 |
liabilities += difference
|