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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
|
| 3 |
+
# --- 1. PASSWORD PROTECTION SCREEN ---
|
| 4 |
+
def check_password():
|
| 5 |
+
"""Returns `True` if the user entered the correct password."""
|
| 6 |
+
def password_entered():
|
| 7 |
+
if st.session_state["password"] == "my_secret_password_123": # Change this password!
|
| 8 |
+
st.session_state["password_correct"] = True
|
| 9 |
+
del st.session_state["password"] # Don't store password
|
| 10 |
+
else:
|
| 11 |
+
st.session_state["password_correct"] = False
|
| 12 |
+
|
| 13 |
+
if "password_correct" not in st.session_state:
|
| 14 |
+
# First run, show input for password
|
| 15 |
+
st.subheader("π Private Accounting Login")
|
| 16 |
+
st.text_input("Enter your password:", type="password", on_change=password_entered, key="password")
|
| 17 |
+
if "password_correct" in st.session_state and not st.session_state["password_correct"]:
|
| 18 |
+
st.error("π Password incorrect")
|
| 19 |
+
return False
|
| 20 |
+
elif not st.session_state["password_correct"]:
|
| 21 |
+
# Incorrect password, show input again
|
| 22 |
+
st.subheader("π Private Accounting Login")
|
| 23 |
+
st.text_input("Enter your password:", type="password", on_change=password_entered, key="password")
|
| 24 |
+
st.error("π Password incorrect")
|
| 25 |
+
return False
|
| 26 |
+
else:
|
| 27 |
+
# Correct password
|
| 28 |
+
return True
|
| 29 |
+
|
| 30 |
+
if not check_password():
|
| 31 |
+
st.stop() # Stop execution here if not logged in
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
# --- 2. ACCOUNTING SYSTEM CLASS ---
|
| 35 |
+
class AccountingSystem:
|
| 36 |
+
def __init__(self):
|
| 37 |
+
if "accounts" not in st.session_state:
|
| 38 |
+
st.session_state.accounts = {
|
| 39 |
+
"1010": {"name": "Cash / Bank", "type": "Asset"},
|
| 40 |
+
"1020": {"name": "Accounts Receivable", "type": "Asset"},
|
| 41 |
+
"2010": {"name": "Accounts Payable", "type": "Liability"},
|
| 42 |
+
"3010": {"name": "Owner's Equity", "type": "Equity"},
|
| 43 |
+
"4010": {"name": "Sales Revenue", "type": "Revenue"},
|
| 44 |
+
"5010": {"name": "Office Supplies & Expenses", "type": "Expense"},
|
| 45 |
+
}
|
| 46 |
+
if "journal_entries" not in st.session_state:
|
| 47 |
+
st.session_state.journal_entries = []
|
| 48 |
+
|
| 49 |
+
def record_transaction(self, date, description, debit_account, credit_account, amount):
|
| 50 |
+
entry = {
|
| 51 |
+
"date": date,
|
| 52 |
+
"description": description,
|
| 53 |
+
"debit_acc": debit_account,
|
| 54 |
+
"credit_acc": credit_account,
|
| 55 |
+
"amount": float(amount)
|
| 56 |
+
}
|
| 57 |
+
st.session_state.journal_entries.append(entry)
|
| 58 |
+
|
| 59 |
+
def get_account_balances(self):
|
| 60 |
+
balances = {acc: 0.0 for acc in st.session_state.accounts}
|
| 61 |
+
|
| 62 |
+
for entry in st.session_state.journal_entries:
|
| 63 |
+
d_acc = entry["debit_acc"]
|
| 64 |
+
c_acc = entry["credit_acc"]
|
| 65 |
+
amt = entry["amount"]
|
| 66 |
+
|
| 67 |
+
if st.session_state.accounts[d_acc]["type"] in ["Asset", "Expense"]:
|
| 68 |
+
balances[d_acc] += amt
|
| 69 |
+
else:
|
| 70 |
+
balances[d_acc] -= amt
|
| 71 |
+
|
| 72 |
+
if st.session_state.accounts[c_acc]["type"] in ["Liability", "Equity", "Revenue"]:
|
| 73 |
+
balances[c_acc] += amt
|
| 74 |
+
else:
|
| 75 |
+
balances[c_acc] -= amt
|
| 76 |
+
|
| 77 |
+
return balances
|
| 78 |
+
|
| 79 |
+
def generate_profit_and_loss(self):
|
| 80 |
+
balances = self.get_account_balances()
|
| 81 |
+
total_revenue = 0.0
|
| 82 |
+
total_expenses = 0.0
|
| 83 |
+
|
| 84 |
+
for acc_code, balance in balances.items():
|
| 85 |
+
acc_type = st.session_state.accounts[acc_code]["type"]
|
| 86 |
+
if acc_type == "Revenue":
|
| 87 |
+
total_revenue += balance
|
| 88 |
+
elif acc_type == "Expense":
|
| 89 |
+
total_expenses += balance
|
| 90 |
+
|
| 91 |
+
net_income = total_revenue - total_expenses
|
| 92 |
+
return {
|
| 93 |
+
"Total Revenue": total_revenue,
|
| 94 |
+
"Total Expenses": total_expenses,
|
| 95 |
+
"Net Profit": net_income
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
def generate_balance_sheet(self):
|
| 99 |
+
balances = self.get_account_balances()
|
| 100 |
+
total_assets = 0.0
|
| 101 |
+
total_liabilities = 0.0
|
| 102 |
+
total_equity = 0.0
|
| 103 |
+
|
| 104 |
+
pnl = self.generate_profit_and_loss()
|
| 105 |
+
net_profit = pnl["Net Profit"]
|
| 106 |
+
|
| 107 |
+
for acc_code, balance in balances.items():
|
| 108 |
+
acc_type = st.session_state.accounts[acc_code]["type"]
|
| 109 |
+
if acc_type == "Asset":
|
| 110 |
+
total_assets += balance
|
| 111 |
+
elif acc_type == "Liability":
|
| 112 |
+
total_liabilities += balance
|
| 113 |
+
elif acc_type == "Equity":
|
| 114 |
+
total_equity += balance
|
| 115 |
+
|
| 116 |
+
total_equity_with_profit = total_equity + net_profit
|
| 117 |
+
|
| 118 |
+
return {
|
| 119 |
+
"Total Assets": total_assets,
|
| 120 |
+
"Total Liabilities": total_liabilities,
|
| 121 |
+
"Total Equity": total_equity_with_profit,
|
| 122 |
+
"Is Balanced": abs(total_assets - (total_liabilities + total_equity_with_profit)) < 0.01
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
# --- 3. STREAMLIT WEB INTERFACE ---
|
| 127 |
+
app = AccountingSystem()
|
| 128 |
+
|
| 129 |
+
st.title("π My Private Accounting Dashboard")
|
| 130 |
+
st.write("Welcome back! Manage your transactions and review your financial health securely.")
|
| 131 |
+
|
| 132 |
+
# Sidebar Navigation
|
| 133 |
+
menu = st.sidebar.selectbox("Navigation", ["Dashboard & Reports", "Add Manual Transaction", "Simulate Bank Feed"])
|
| 134 |
+
|
| 135 |
+
if menu == "Dashboard & Reports":
|
| 136 |
+
st.subheader("π Financial Statements")
|
| 137 |
+
|
| 138 |
+
col1, col2 = st.columns(2)
|
| 139 |
+
|
| 140 |
+
# Profit & Loss Card
|
| 141 |
+
with col1:
|
| 142 |
+
st.markdown("### Profit & Loss")
|
| 143 |
+
pnl = app.generate_profit_and_loss()
|
| 144 |
+
st.metric(label="Total Revenue", value=f"${pnl['Total Revenue']:,.2f}")
|
| 145 |
+
st.metric(label="Total Expenses", value=f"${pnl['Total Expenses']:,.2f}")
|
| 146 |
+
st.metric(label="Net Profit", value=f"${pnl['Net Profit']:,.2f}")
|
| 147 |
+
|
| 148 |
+
# Balance Sheet Card
|
| 149 |
+
with col2:
|
| 150 |
+
st.markdown("### Balance Sheet")
|
| 151 |
+
bs = app.generate_balance_sheet()
|
| 152 |
+
st.metric(label="Total Assets", value=f"${bs['Total Assets']:,.2f}")
|
| 153 |
+
st.metric(label="Total Liabilities", value=f"${bs['Total Liabilities']:,.2f}")
|
| 154 |
+
st.metric(label="Total Equity", value=f"${bs['Total Equity']:,.2f}")
|
| 155 |
+
st.info(f"Books Balanced: {bs['Is Balanced']}")
|
| 156 |
+
|
| 157 |
+
st.markdown("---")
|
| 158 |
+
st.subheader("π Recent Transaction History")
|
| 159 |
+
if st.session_state.journal_entries:
|
| 160 |
+
st.table(st.session_state.journal_entries)
|
| 161 |
+
else:
|
| 162 |
+
st.write("No transactions recorded yet. Use the sidebar to add some!")
|
| 163 |
+
|
| 164 |
+
elif menu == "Add Manual Transaction":
|
| 165 |
+
st.subheader("βοΈ Record a New Transaction")
|
| 166 |
+
|
| 167 |
+
with st.form("transaction_form"):
|
| 168 |
+
date = st.date_input("Transaction Date")
|
| 169 |
+
description = st.text_input("Description (e.g., Client Payment, Rent)")
|
| 170 |
+
|
| 171 |
+
account_options = {f"{k} - {v['name']}": k for k, v in st.session_state.accounts.items()}
|
| 172 |
+
debit_choice = st.selectbox("Debit Account", list(account_options.keys()))
|
| 173 |
+
credit_choice = st.selectbox("Credit Account", list(account_options.keys()))
|
| 174 |
+
|
| 175 |
+
amount = st.number_input("Amount ($)", min_value=0.01, format="%.2f")
|
| 176 |
+
|
| 177 |
+
submitted = st.form_submit_button("Record Transaction")
|
| 178 |
+
if submitted:
|
| 179 |
+
d_acc = account_options[debit_choice]
|
| 180 |
+
c_acc = account_options[credit_choice]
|
| 181 |
+
app.record_transaction(str(date), description, d_acc, c_acc, amount)
|
| 182 |
+
st.success("Transaction successfully recorded!")
|
| 183 |
+
|
| 184 |
+
elif menu == "Simulate Bank Feed":
|
| 185 |
+
st.subheader("π¦ Bank Sync Simulation")
|
| 186 |
+
st.write("Simulate automatic imports from your bank account webhooks.")
|
| 187 |
+
|
| 188 |
+
if st.button("Run Bank Sync Now"):
|
| 189 |
+
# Simulated incoming transactions
|
| 190 |
+
sample_bank_data = [
|
| 191 |
+
("2026-06-02", "Client Web Design Deposit", 1500.00),
|
| 192 |
+
("2026-06-03", "Office Depot Supplies", -125.50),
|
| 193 |
+
("2026-06-04", "Coworking Space Rent", -400.00)
|
| 194 |
+
]
|
| 195 |
+
|
| 196 |
+
for date, desc, amt in sample_bank_data:
|
| 197 |
+
if amt > 0:
|
| 198 |
+
app.record_transaction(date, desc, "1010", "4010", amt)
|
| 199 |
+
else:
|
| 200 |
+
app.record_transaction(date, desc, "5010", "1010", abs(amt))
|
| 201 |
+
|
| 202 |
+
st.success("Successfully synced 3 new transactions from bank feed!")
|