import streamlit as st import pandas as pd from utils import * from data import * from io import BytesIO def fullColor(): df = pd.DataFrame(full_data) if "entries" not in st.session_state: st.session_state.entries = [] 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") company_choice = st.selectbox("Select Company", list(full_data.keys()), key="emb_company") if company_choice: df = pd.DataFrame(full_data[company_choice]) col1, col2, col3 = st.columns(3) with col1: quantity = st.number_input("Enter Quantity", min_value=1, step=1, key="quantity") with col2: stitch_count = st.selectbox( "Select Stitch Count", options=list(df.columns[1:]), key="stitch_count" ) with col3: item_price = st.number_input('Item Cost (Fixed)', min_value=0.0, step=0.01, key="item_price") 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}%" quantity_labels = df["Quantity"].tolist() selected_range = find_quantity_range(quantity, quantity_labels) stitch_price = df[df["Quantity"] == selected_range][stitch_count].values[0] # Calculate Net Value Before Margin Selection net_value = quantity * (item_price + stitch_price) unit_net_cost = item_price + stitch_price net_value = unit_net_cost * quantity if st.button("βž• Add Entry"): if quantity and stitch_count and item_price: total_selling_price = net_value / (1 - margin) unit_selling_price = total_selling_price / quantity entry = { "Brand Name": brand_name, "Selected Date": cur_date, "Quantity": quantity, "Stitch Count": stitch_count, "Stitch Price": stitch_price, "Total Net Cost": f"${net_value:,.2f}", "Net Cost (per unit)": f"${unit_net_cost:.2f}", "Margin": margin_display, "Unit Selling Price": f"${unit_selling_price:.2f}", "Total Selling Price": f"${total_selling_price:.2f}" } st.session_state.entries.append(entry) if st.session_state.entries: #st.subheader("Full Color Pricing Breakdown") st.markdown(f"

{brand_name}

", unsafe_allow_html=True) cols = st.columns(len(st.session_state.entries)) for i, (col, entry) in enumerate(zip(cols, st.session_state.entries)): 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"
πŸͺ‘ Stitch Price (per unit):
{entry['Stitch Price']}

", unsafe_allow_html=True) st.markdown(f"
πŸͺ™ Net Cost (per unit):
{entry['Net Cost (per unit)']}

", unsafe_allow_html=True) st.markdown(f"
πŸ’° Total Net Cost:
{entry['Total Net Cost']}

", unsafe_allow_html=True) st.markdown(f"
πŸ“ˆ Margin:
{entry['Margin']}

", unsafe_allow_html=True) st.markdown(f"
πŸ“Š Unit Price:
{entry['Unit Selling Price']}

", unsafe_allow_html=True) st.markdown(f"
πŸ’° Total Selling Price:
{entry['Total Selling Price']}

", unsafe_allow_html=True) if st.button(f"❌ Delete {i+1}", key=f"delete_{i}"): del st.session_state.entries[i] st.rerun() if st.button("πŸ”„ Reset Entries"): st.session_state.entries = [] st.rerun() entries = st.session_state.get("entries", []) if entries: st.markdown(""" """, unsafe_allow_html=True) df = pd.DataFrame(entries) df = df[[ 'Quantity', 'Stitch Price', 'Net Cost (per unit)', 'Total Net Cost', 'Margin', 'Unit Selling Price', 'Total Selling Price', 'Selected Date' ]] output = BytesIO() with pd.ExcelWriter(output, engine='xlsxwriter') as writer: df.to_excel(writer, index=False, startrow=3, sheet_name='Fullcolor Breakdown') workbook = writer.book worksheet = writer.sheets['Fullcolor Breakdown'] header_format = workbook.add_format({'bold': True, 'font_color': '#d31145', 'font_size': 14}) worksheet.write('A1', brand_name, header_format) #worksheet.write('A2', cur_date) processed_data = output.getvalue() output.seek(0) st.download_button( label="πŸ“₯ Download Results as Excel", data=output, file_name='fullcolor.xlsx', mime='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', key="excel-download", help="Download fullcolor pricing breakdown as an Excel file" ) # if entries: # st.subheader("") # html = """ # # # # # # # # # # # # """ # st.components.v1.html(html, height=130)