File size: 11,768 Bytes
73df08c
 
 
 
f909f76
73df08c
 
 
 
907833c
 
 
 
 
73df08c
 
 
f8be578
73df08c
 
 
 
 
 
 
 
 
 
 
 
 
 
f8be578
73df08c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cc60c65
 
 
 
 
 
 
73df08c
 
 
 
 
 
 
 
907833c
 
73df08c
 
 
 
 
 
 
f8be578
73df08c
 
 
cc60c65
73df08c
 
 
 
 
 
 
 
 
907833c
 
73df08c
 
 
 
 
 
 
f8be578
cc60c65
 
73df08c
 
 
 
 
 
 
 
 
 
 
f909f76
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
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"<h4 style='color: #f1c40f';>{brand_name}</h4>", 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"<h4 style='color: #d31145;'>Entry {i+1}</h4>", unsafe_allow_html=True)
                st.markdown(f"<div style='font-size: 16px;'>πŸ“Œ Quantity:<br><b>{entry['Quantity']}</b></div><br>", unsafe_allow_html=True)
                st.markdown(f"<div style='font-size: 16px;'>πŸ–¨οΈ Screen Print Total:<br><b>{entry['SP Total Price']}</b></div><br>", unsafe_allow_html=True)
                st.markdown(f"<div style='font-size: 16px;'>🎨 Full Colour Price:<br><b>{entry['FC Price']}</b></div><br>", unsafe_allow_html=True)
                st.markdown(f"<div style='font-size: 16px;'>πŸͺ™ Net Cost (per unit):<br><b>{entry['Net Cost (per unit)']}</b></div><br>", unsafe_allow_html=True)
                st.markdown(f"<div style='font-size: 16px;'>πŸ’° Total Net Cost:<br><b>{entry['Total Net Cost']}</b></div><br>", unsafe_allow_html=True)
                st.markdown(f"<div style='font-size: 16px;'>πŸ“ˆ Margin:<br><b>{entry['Margin']}</b></div><br>", unsafe_allow_html=True)
                st.markdown(f"<div style='font-size: 16px;'>πŸ“Š Unit Price:<br><b>{entry['Unit Selling Price']}</b></div><br>", unsafe_allow_html=True)
                st.markdown(f"<div style='font-size: 16px;'>πŸ’΅ Total Selling Price:<br><b>{entry['Total Selling Price']}</b></div><br>", 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("""

                <style>

                .excel-button {

                    background-color: #d31145;

                    color: white;

                    padding: 12px 24px;

                    border: none;

                    border-radius: 8px;

                    font-size: 14px;

                    font-weight: bold;

                    cursor: pointer;

                    transition: background-color 0.3s ease;

                    box-shadow: 0 2px 5px rgba(0,0,0,0.2);

                }

                .excel-button:hover {

                    background-color: #b80e3a;

                }

                </style>

            """, 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 = """
        #                 <html>
        #                 <head>
        #                 <script src="https://cdnjs.cloudflare.com/ajax/libs/html2pdf.js/0.10.1/html2pdf.bundle.min.js"></script>
        #                 <style>
        #                     .pdf-button {{
        #                         background-color: #d31145;
        #                         color: white;
        #                         padding: 12px 24px;
        #                         border: none;
        #                         border-radius: 8px;
        #                         font-size: 14px;
        #                         font-weight: bold;
        #                         cursor: pointer;
        #                         transition: background-color 0.3s ease;
        #                         box-shadow: 0 2px 5px rgba(0,0,0,0.2);
        #                     }}
        #                     .pdf-button:hover {{
        #                         background-color: #b80e3a;
        #                     }}
        #                 </style>
        #                 </head>
        #                 <body>

        #                 <div id="pdf-content" style="display: none;">
        #                     <h4 style='color:#d31145;'>{brand_name}</h4>
        #                     <p>{cur_date}</p>
        #                 """.format(brand_name=brand_name, cur_date=cur_date)

        # for i, entry in enumerate(entries):
        #     html += f"""
        #     <div style='margin-bottom: 20px; border:1px solid #ccc; padding: 10px; border-radius: 8px;'>
        #         <h4 style='color:#d31145;'>Entry {i+1}</h4>
        #         <p>πŸ“Œ Quantity: {entry['Quantity']}</p>
        #         <p>πŸ–¨οΈ Screen Print Type: {entry['Print Type']}</p>
        #         <p>πŸ“ Print Size: {entry['Print Size']}</p>
        #         <p>βš™οΈ Options: {entry['SP Options']}</p>
        #         <p>πŸ’Έ Screen Print Total: {entry['SP Total Price']}</p>
        #         <p>🎨 Full Colour Area: {entry['Full Colour Area']}</p>
        #         <p>πŸ–οΈ Full Colour Price: {entry['FC Price']}</p>
        #         <p>πŸ’° Total Net Cost: {entry['Total Net Cost']}</p>
        #         <p>πŸ“ˆ Margin: {entry['Margin']}</p>
        #         <p>πŸ“Š Unit Price: {entry['Unit Selling Price']}</p>
        #         <p>πŸ’΅ Total Selling Price: {entry['Total Selling Price']}</p>
        #     </div>
        #     """

        # html += """
        # </div>
        # <button class="pdf-button" onclick="downloadPDF()">πŸ“„ Download Results as PDF</button>
        # <script>
        # function downloadPDF() {
        #     const element = document.getElementById("pdf-content");
        #     element.style.display = 'block';
        #     html2pdf().set({
        #         margin: 0.5,
        #         filename: 'combo_screenprint_fullcolor_breakdown.pdf',
        #         image: { type: 'jpeg', quality: 0.98 },
        #         html2canvas: { scale: 2 },
        #         jsPDF: { unit: 'in', format: 'letter', orientation: 'portrait' }
        #     }).from(element).save().then(() => {
        #         element.style.display = 'none';
        #     });
        # }
        # </script>

        # </body>
        # </html>
        # """
        # st.components.v1.html(html, height=120)