Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,42 +1,29 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
|
| 4 |
-
|
| 5 |
-
st.set_page_config(page_title="Business Expense Tracker", layout="centered")
|
| 6 |
|
| 7 |
-
|
|
|
|
| 8 |
|
| 9 |
-
#
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
-
#
|
| 14 |
-
|
| 15 |
-
date = st.date_input("Date")
|
| 16 |
-
sales = st.number_input("Sales (โน)", min_value=0.0, step=100.0)
|
| 17 |
-
expenses = st.number_input("Expenses (โน)", min_value=0.0, step=100.0)
|
| 18 |
|
| 19 |
-
if
|
| 20 |
-
|
| 21 |
-
st.session_state.records.append({"Date": date, "Sales": sales, "Expenses": expenses, "Profit": profit})
|
| 22 |
-
st.success(f"Record added: Profit = โน{profit:.2f}")
|
| 23 |
-
|
| 24 |
-
# Display table if records exist
|
| 25 |
-
if st.session_state.records:
|
| 26 |
-
df = pd.DataFrame(st.session_state.records)
|
| 27 |
-
|
| 28 |
-
st.subheader("๐ Expense Records")
|
| 29 |
st.dataframe(df, use_container_width=True)
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
st.
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
total_profit = df["Profit"].sum()
|
| 36 |
-
|
| 37 |
-
st.write(f"*Total Sales:* โน{total_sales:.2f}")
|
| 38 |
-
st.write(f"*Total Expenses:* โน{total_expenses:.2f}")
|
| 39 |
-
st.write(f"*Total Profit:* โน{total_profit:.2f}")
|
| 40 |
-
|
| 41 |
-
# Chart
|
| 42 |
-
st.line_chart(df.set_index("Date")[["Sales", "Expenses", "Profit"]])
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
|
| 4 |
+
st.title("๐๏ธ Small Business / Xpense Tracker")
|
|
|
|
| 5 |
|
| 6 |
+
# Number of products
|
| 7 |
+
num_products = st.number_input("Enter number of products:", min_value=1, step=1)
|
| 8 |
|
| 9 |
+
# Store data
|
| 10 |
+
products = []
|
| 11 |
+
for i in range(int(num_products)):
|
| 12 |
+
st.subheader(f"Product {i+1}")
|
| 13 |
+
name = st.text_input(f"Name of Product {i+1}", key=f"name{i}")
|
| 14 |
+
expense = st.number_input(f"Expense for {name or f'Product {i+1}'}", min_value=0.0, step=0.01, key=f"exp{i}")
|
| 15 |
+
sales = st.number_input(f"Sales for {name or f'Product {i+1}'}", min_value=0.0, step=0.01, key=f"sale{i}")
|
| 16 |
+
profit = sales - expense
|
| 17 |
+
products.append({"Product": name or f"Product {i+1}", "Expense": expense, "Sales": sales, "Profit": profit})
|
| 18 |
|
| 19 |
+
# Convert to DataFrame
|
| 20 |
+
df = pd.DataFrame(products)
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
+
if not df.empty:
|
| 23 |
+
st.subheader("๐ Product-wise Details")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
st.dataframe(df, use_container_width=True)
|
| 25 |
+
|
| 26 |
+
st.subheader("๐ Totals")
|
| 27 |
+
st.write(f"**Total Expenses:** {df['Expense'].sum():.2f}")
|
| 28 |
+
st.write(f"**Total Sales:** {df['Sales'].sum():.2f}")
|
| 29 |
+
st.write(f"**Total Profit:** {df['Profit'].sum():.2f}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|