File size: 1,605 Bytes
dc7d390
 
 
af4a9aa
 
 
dc7d390
c5eafd6
 
dc7d390
af4a9aa
c5eafd6
 
 
 
 
 
 
 
dc7d390
c5eafd6
 
dc7d390
c5eafd6
 
dc7d390
c5eafd6
 
af4a9aa
 
 
 
 
 
 
 
aa7a52e
af4a9aa
 
aa7a52e
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import streamlit as st
import pandas as pd

st.set_page_config(page_title="Xpense Tracker", page_icon="πŸ’°", layout="centered")

st.title("πŸ›οΈ Small Business / Xpense Tracker")

# Number of products
num_products = st.number_input("Enter number of products:", min_value=1, step=1)

# Store product data
products = []
for i in range(int(num_products)):
    st.subheader(f"Product {i+1}")
    name = st.text_input(f"Name of Product {i+1}", key=f"name{i}")
    expense = st.number_input(f"Expense for {name or f'Product {i+1}'}", min_value=0.0, step=0.01, key=f"exp{i}")
    sales = st.number_input(f"Sales for {name or f'Product {i+1}'}", min_value=0.0, step=0.01, key=f"sale{i}")
    profit = sales - expense
    products.append({"Product": name or f"Product {i+1}", "Expense": expense, "Sales": sales, "Profit": profit})

# Convert to DataFrame
df = pd.DataFrame(products)

if not df.empty:
    st.subheader("πŸ“Š Product-wise Details")
    st.dataframe(df, use_container_width=True)

    st.subheader("πŸ“ˆ Totals")
    total_expense = df['Expense'].sum()
    total_sales = df['Sales'].sum()
    total_profit = df['Profit'].sum()

    st.write(f"**Total Expenses:** {total_expense:.2f}")
    st.write(f"**Total Sales:** {total_sales:.2f}")
    st.write(f"**Total Profit:** {total_profit:.2f}")

    # πŸ“Š Simple Streamlit Graphs
    st.subheader("πŸ“Š Visual Analysis")

    # Bar chart comparing Expenses, Sales, Profit
    st.bar_chart(df.set_index("Product")[["Expense", "Sales", "Profit"]])

    # Line chart for trends (optional)
    st.line_chart(df.set_index("Product")[["Sales", "Profit"]])