File size: 12,620 Bytes
44f3a8a
 
 
 
f909f76
44f3a8a
 
 
 
907833c
 
 
 
 
44f3a8a
 
 
 
 
73df08c
 
 
 
 
 
 
 
 
 
 
44f3a8a
 
 
cc60c65
 
 
 
 
44f3a8a
 
73df08c
 
 
 
 
 
 
 
 
 
 
 
 
cc60c65
73df08c
 
 
 
 
 
 
907833c
 
73df08c
 
 
 
 
 
 
 
cc60c65
73df08c
 
 
 
 
 
 
 
907833c
 
73df08c
 
 
 
 
 
 
cc60c65
73df08c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f909f76
 
 
73df08c
 
 
 
 
 
 
 
 
 
f909f76
 
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
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"<h4 style='color: #f1c40f';>{brand_name}</h4>", 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"<h4 style='color: #d31145;'>Entry {i+1}</h4>", unsafe_allow_html=True)
                            st.markdown(f"<div style='font-size: 16px;'>πŸ“Œ <strong>Quantity:</strong><br> {entry['Quantity']}</div><br>", unsafe_allow_html=True)
                            st.markdown(f"<div style='font-size: 16px;'>πŸ“ <strong>Print Size:</strong><br> {entry['Print Size']}</div><br>", unsafe_allow_html=True)
                            st.markdown(f"<div style='font-size: 16px;'>πŸͺ‘ <strong>Print Cost (Per Unit):</strong><br> ${entry['Base Price Per Unit']:.2f}</div><br>", unsafe_allow_html=True)
                            st.markdown(f"<div style='font-size: 16px;'>πŸͺ™ <strong>Net Cost (per unit):</strong><br> ${entry['Net Cost (per unit)']:.2f}</div><br>", unsafe_allow_html=True)
                            st.markdown(f"<div style='font-size: 16px;'>πŸ’° <strong>Total Net Cost:</strong><br> ${entry['Total Cost']:.2f}</div><br>", unsafe_allow_html=True)
                            st.markdown(f"<div style='font-size: 16px;'>πŸ“Š <strong>Margin:</strong><br> {entry['Margin'] * 100:.2f}%</div><br>", unsafe_allow_html=True)
                            st.markdown(f"<div style='font-size: 16px;'>πŸ’Έ <strong>Unit Selling Price:</strong><br> ${entry['Unit Price After Margin']:.2f}</div><br>", unsafe_allow_html=True)
                            st.markdown(f"<div style='font-size: 16px;'>πŸ’΅ <strong>Total Selling Price:</strong><br> ${entry['Total Selling Price']:.2f}</div><br>", unsafe_allow_html=True)

                            # Delete Button
                            if st.button(f"❌ Delete {i+1}", key=f"delete_screenprint_{i}"):
                                del st.session_state.entries_screenprint[i]
                                st.rerun()

                    if st.button("πŸ”„ Reset Entries"):
                        st.session_state.entries_screenprint = []
                        st.rerun()

                    entries = st.session_state.get("entries_screenprint", [])
                    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', 'Print Size', 'Base Price Per Unit', 'Net Cost (per unit)', 'Total Cost',
                            'Margin', 'Unit Price After Margin', '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 Breakdown')
                            workbook = writer.book
                            worksheet = writer.sheets['Screenprint 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='screenprint.xlsx',
                            mime='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
                            key="excel-download",
                            help="Download screenprint pricing breakdown as an Excel file"
                        )
                    # if entries:
                    #     st.subheader("")

                    #     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>πŸ“ Print Size: {entry['Print Size']}</p>
                    #             <p>πŸͺ‘ Print Cost (Per Unit): ${entry['Base Price Per Unit']:.2f}</p>
                    #             <p>πŸ’° Total Net Cost: ${entry['Total Cost']:.2f}</p>
                    #             <p>πŸ“Š Margin: {entry['Margin'] * 100:.2f}%</p>
                    #             <p>πŸ’Έ Unit Selling Price: ${entry['Unit Price After Margin']:.2f}</p>
                    #             <p>πŸ’΅ Total Selling Price: ${entry['Total Selling Price']:.2f}</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: 'pricing_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=100)