import streamlit as st import pandas as pd from utils import * from data import * from io import BytesIO def screenFull(): if "screen_full_entries" not in st.session_state: st.session_state.screen_full_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") # Select Companies sp_company = st.selectbox("Select Screen Print Company", list(screen_data.keys()), key="combo_screen_full_sp_company") fc_company = st.selectbox("Select Full Colour Company", list(full_data.keys()), key="combo_screen_full_fc_company") sp_data = screen_data[sp_company] df_fc = pd.DataFrame(full_data[fc_company]) col1, col2, col3 = st.columns(3) with col1: selected_type = st.selectbox("Print Type", list(sp_data.keys()), key="combo_screen_full_print_type") with col2: selected_size = st.selectbox("Print Size", list(sp_data[selected_type].columns[1:4]), key="combo_screen_full_print_size") with col3: selected_options = st.multiselect("Options", ["Darks", "Fleece", "90% Poly+", "Sleeves & Legs"], key="combo_screen_full_options") col4, col5, col6 = st.columns(3) with col4: print_area = st.selectbox("Full Colour Print", list(df_fc.columns[1:]), key="combo_screen_full_print_area") with col5: quantity = st.number_input("Enter Quantity", min_value=1, step=1, key="combo_screen_full_quantity") with col6: item_price = st.number_input("Item Cost (Fixed)", min_value=0.0, step=0.01, key="combo_screen_full_item_price") # Calculate Prices # --- Screen Print --- sp_df = sp_data[selected_type] sp_range = next((row["Qty"] for _, row in sp_df.iterrows() if quantity <= int(row["Qty"].split()[-1])), sp_df.iloc[-1]["Qty"]) sp_row = sp_df[sp_df["Qty"] == sp_range] sp_base_price = sp_row[selected_size].values[0] if not sp_row.empty else 0.0 sp_option_cost = sum(sp_row[opt].values[0] for opt in selected_options if opt in sp_row) if not sp_row.empty else 0.0 sp_total_price = sp_base_price + sp_option_cost # --- Full Color --- quantity_labels_fc = df_fc["Quantity"].tolist() fc_range = find_quantity_range(quantity, quantity_labels_fc) fc_print_price = float(df_fc[df_fc["Quantity"] == fc_range][print_area].values[0]) total_deco_price = sp_total_price + fc_print_price net_value = quantity * (item_price + total_deco_price) unit_net_cost = item_price + total_deco_price net_value = unit_net_cost * quantity margin_percentage = st.number_input("Enter Margin (%)", min_value=1.0, max_value=99.0, step=0.1, value=40.0, key="combo_screen_full_margin_val") margin = margin_percentage / 100 margin_display = f"{margin_percentage:.2f}%" total_selling_price = net_value / (1 - margin) unit_selling_price = total_selling_price / quantity # Add Entry if st.button("➕ Add Entry", key="add_screen_full_entry"): entry = { "Brand Name": brand_name, "Selected Date": cur_date, "Quantity": quantity, "Print Type": selected_type, "Print Size": selected_size, "SP Base Price": f"${sp_base_price:.2f}", "SP Options": ", ".join(selected_options) if selected_options else "None", "SP Option Price": f"${sp_option_cost:.2f}", "SP Total Price": f"${sp_total_price:.2f}", "Full Colour Area": print_area, "FC Price": f"${fc_print_price:.2f}", "Total Decoration Cost": f"${total_deco_price:.2f}", "Item Cost": f"${item_price:.2f}", "Net Cost (per unit)": f"${unit_net_cost:.2f}", "Total Net Cost": f"${net_value:,.2f}", "Margin": margin_display, "Unit Selling Price": f"${unit_selling_price:.2f}", "Total Selling Price": f"${total_selling_price:.2f}" } st.session_state.screen_full_entries.append(entry) # Display Breakdown if st.session_state.screen_full_entries: #st.subheader("Pricing Breakdown") st.markdown(f"

{brand_name}

", unsafe_allow_html=True) entries = st.session_state.screen_full_entries cols = st.columns(len(entries)) for i, (col, entry) in enumerate(zip(cols, 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"
🖨️ Screen Print Total:
{entry['SP Total Price']}

", unsafe_allow_html=True) st.markdown(f"
🎨 Full Colour Price:
{entry['FC 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_screen_full_{i}"): del st.session_state.screen_full_entries[i] st.rerun() if st.button("🔄 Reset Entries", key="reset_screen_full"): st.session_state.screen_full_entries = [] st.rerun() entries = st.session_state.get("screen_full_entries", []) if entries: st.markdown(""" """, unsafe_allow_html=True) df = pd.DataFrame(entries) df = df[[ 'Quantity', 'SP Total Price', 'FC 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='Screenprint Fullcolor Breakdown') workbook = writer.book worksheet = writer.sheets['Screenprint 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='embroideryFullcolor.xlsx', mime='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', key="excel-download", help="Download screenprint fullcolor pricing breakdown as an Excel file" ) # html = """ # # # # # # # # # # # # """ # st.components.v1.html(html, height=120)