import streamlit as st
import pandas as pd
from utils import *
from data import *
from io import BytesIO
def screenPrint():
if "entries_screenprint" not in st.session_state:
st.session_state.entries_screenprint = []
col1, col2 = st.columns(2)
with col1:
brand_name = st.text_input("Brand Name", key="brand_name")
with col2:
cur_date = st.date_input("Date", value="today", key="quote_date")
selected_company = st.selectbox("Select Company", list(screen_data.keys()))
if selected_company:
company_data = screen_data[selected_company]
col1, col2, col3, col4 = st.columns(4)
# selected_type = col1.selectbox("Print Type", list(company_data.keys()))
# selected_size = col2.selectbox("Print Size", list(company_data[selected_type].columns[1:4]))
selected_types = col1.multiselect("Print Type", list(company_data.keys()))
selected_type = selected_types[0] if selected_types else None
selected_sizes = col2.multiselect(
"Print Size",
list(company_data[selected_type].columns[1:4]) if selected_type else []
)
selected_size = selected_sizes[0] if selected_sizes else None
quantity = col3.number_input("Quantity", min_value=1, step=1)
selected_options = col4.multiselect("Options", ["Darks", "Fleece", "90% Poly+", "Sleeves & Legs"])
item_cost = st.number_input("Enter Base Item Cost", min_value=0.0, step=0.01)
margin_percentage = st.number_input("Enter Margin (%)", min_value=1.0, max_value=99.0, step=0.1, value=40.0)
margin = margin_percentage / 100
margin_display = f"{margin_percentage:.2f}%"
# --- Determine Range ---
if selected_type and selected_size and quantity and item_cost:
df = company_data[selected_type]
selected_range = next((row["Qty"] for _, row in df.iterrows() if quantity <= int(row["Qty"].split()[-1])), df.iloc[-1]["Qty"])
row = df[df["Qty"] == selected_range]
if not row.empty and item_cost > 0:
base_price = row[selected_size].values[0]
unit_price_before_margin = base_price + item_cost
for option in selected_options:
if option in row:
unit_price_before_margin += row[option].values[0]
total_cost = unit_price_before_margin * quantity
total_selling_price = total_cost / (1 - margin)
unit_price_after_margin = total_selling_price / quantity
if st.button("➕ Add Entry"):
entry = {
"Brand Name": brand_name,
"Selected Date": cur_date,
"Quantity": quantity,
"Company": selected_company,
"Print Type": selected_type,
"Print Size": selected_size,
"Options": ", ".join(selected_options) if selected_options else "None",
"Item Cost": item_cost,
"Base Price Per Unit": base_price,
"Total Cost": total_cost,
"Net Cost (per unit)": unit_price_before_margin,
"Margin": margin,
"Unit Price After Margin": unit_price_after_margin,
"Total Selling Price": total_selling_price
}
st.session_state.entries_screenprint.append(entry)
# --- Display Pricing Breakdown ---
if st.session_state.entries_screenprint:
#st.subheader("Pricing Breakdown")
st.markdown(f"
{brand_name}
", unsafe_allow_html=True)
cols = st.columns(len(st.session_state.entries_screenprint)) # Create one column per entry
for i, (col, entry) in enumerate(zip(cols, st.session_state.entries_screenprint)):
with col:
st.markdown(f"
Entry {i+1}
", unsafe_allow_html=True)
st.markdown(f"
📌 Quantity: {entry['Quantity']}
", unsafe_allow_html=True)
st.markdown(f"
📏 Print Size: {entry['Print Size']}
", unsafe_allow_html=True)
st.markdown(f"
🪡 Print Cost (Per Unit): ${entry['Base Price Per Unit']:.2f}
", unsafe_allow_html=True)
st.markdown(f"
🪙 Net Cost (per unit): ${entry['Net Cost (per unit)']:.2f}
", unsafe_allow_html=True)
st.markdown(f"
💰 Total Net Cost: ${entry['Total Cost']:.2f}
", unsafe_allow_html=True)
st.markdown(f"
📊 Margin: {entry['Margin'] * 100:.2f}%
", unsafe_allow_html=True)
st.markdown(f"
💸 Unit Selling Price: ${entry['Unit Price After Margin']:.2f}
", unsafe_allow_html=True)
st.markdown(f"
💵 Total Selling Price: ${entry['Total Selling Price']:.2f}