Ninad077 commited on
Commit
246e086
·
verified ·
1 Parent(s): c529621

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +163 -0
app.py ADDED
@@ -0,0 +1,163 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ from datetime import datetime
4
+ import sys
5
+ sys.path.append('/Users/ninadmandavkar/Desktop/Fynd')
6
+ from plan_maker.config import fee_config, var_config, char_config
7
+ import os
8
+
9
+ # Function to initialize session state
10
+ def initialize_session_state():
11
+ if 'data' not in st.session_state:
12
+ st.session_state.data = {}
13
+
14
+ # Function to save user data
15
+ def save_user_data(user_name, data):
16
+ st.session_state.data[user_name] = data
17
+
18
+ # Function to display saved records as a table
19
+ def display_saved_records():
20
+ st.title("Saved Records")
21
+ df = pd.DataFrame.from_dict(st.session_state.data, orient='index')
22
+ st.write(df)
23
+
24
+ # Save records to CSV
25
+ if not df.empty:
26
+ folder_path = "data" # Folder name
27
+ os.makedirs(folder_path, exist_ok=True) # Create folder if it doesn't exist
28
+ file_path = os.path.join(folder_path, "records.csv")
29
+ df.to_csv(file_path, index=False)
30
+
31
+ st.download_button(
32
+ label="Download CSV",
33
+ data=open(file_path, 'rb').read(),
34
+ file_name="records.csv",
35
+ mime="text/csv",
36
+ )
37
+
38
+ # Initialize session state
39
+ initialize_session_state()
40
+
41
+ # User name & email id
42
+ user_name = st.sidebar.text_input("Enter your name:")
43
+
44
+ # Section 1: Plan Info
45
+ st.sidebar.title("Section 1: Plan Info")
46
+ plan_name = st.sidebar.text_input("Plan Name", help="Enter the name of the plan")
47
+ plan_description = st.sidebar.text_area("Plan Description", max_chars=250, help="Describe the plan")
48
+ plan_start_date = st.sidebar.date_input("Plan Start Date", value=datetime.now(), help="Select the start date of the plan")
49
+ a1 = ["GoFynd", "Uniket", "B2B", "Marketplaces", "StoreOS", "Website", "ONDC", "OMS", "TMS", "WMS", "GMC", "Catalog Cloud"]
50
+ ordering_channels = st.sidebar.selectbox("Product lines", ["--please select--"]+a1, help="Select the ordering channels")
51
+
52
+
53
+ # Section 2: Company Info
54
+ st.sidebar.title("Section 2: Company Info")
55
+ company_id = st.sidebar.text_input("Company ID", help="Enter the company ID")
56
+ company_name = st.sidebar.text_input("Company Name", help="Enter the company name")
57
+
58
+ # Layer 1: Mapping of Ordering channels with Fulfilling location
59
+ if "TMS" in ordering_channels or "GMC" in ordering_channels or "Catalog Cloud" in ordering_channels:
60
+ fulfilling_location = None
61
+ application_id = None
62
+ else:
63
+ abc = ["Store", "Warehouse"]
64
+ fulfilling_location = st.sidebar.selectbox("Fulfilling Location", abc, help="Select the fulfilling location")
65
+ application_id = st.sidebar.text_input("Application ID", key="application_id_input", help="Enter the application ID")
66
+
67
+
68
+ # Section 3: Defining products for each dropdown
69
+ product_options = ["B2B", "Marketplaces", "StoreOS", "Website", "ONDC", "OMS", "TMS", "WMS", "GMC", "Catalog Cloud"]
70
+ fee_type_options = ["Development", "Subscription", "Maintenance", "Transaction", "Minimum Guarantee", "Logistics", "Packaging", "SLA", "Licensing"]
71
+ fee_nature_options = ["Fixed %", "Flat currency","Slab based"]
72
+ variable_options = ["Bag", "Order", "Shipment", "Application", "Extension", "Integration", "Store", "User"]
73
+ chargeable_on_options = ["Developed", "Installed", "Placed", "Invoiced", "Delivered", "Return window", "All", "Picked", "RTO", "DTO", "Packed"]
74
+ plan_validity_options = ["One time", "Monthly", "Quarterly", "Bi-Annually", "Annually"]
75
+ payment_method_options = ["Prepaid", "Postpaid"]
76
+
77
+
78
+ # Create a layout with two columns
79
+ col1, col2, col3 = st.columns([1, 3, 2])
80
+
81
+ # In the first column, display the image
82
+ with col1:
83
+ st.image("Fynd copy.png", width=200)
84
+
85
+ st.title(":violet[Plan maker]")
86
+
87
+
88
+ # 2nd layer: Mapping of Ordering channels with fee types
89
+ fee_type_mapping = fee_config['fee_type_mapping']
90
+ selected_fee_type = st.selectbox("Fee Type", ["--please select--"] + fee_type_mapping.get(ordering_channels, []), help="Select the type of fee")
91
+
92
+
93
+ # 3rd layer mapping: Mapping of Fee type with variables
94
+ variable_type_mapping = var_config["variable_type_mapping"]
95
+ selected_variable_type = st.selectbox("Variable Type", ["--please select--"] + variable_type_mapping.get(selected_fee_type, []), help="Select the type of variable")
96
+
97
+
98
+ # 4th layer mapping: Mapping of Fee type with variables
99
+ chargeable_on_mapping = char_config["chargeable_on_mapping"]
100
+ selected_chargeable_on = st.selectbox("Chargeable on", ["--please select--"] + chargeable_on_mapping.get(selected_variable_type, []), help="Select the type of Chargeable")
101
+
102
+ # 5th layer: Mapping of fee types with variables and chargeable on
103
+ selected_fee_nature = st.selectbox("Fee Nature", ["--please select--"]+fee_nature_options, help="Select the fee nature")
104
+
105
+
106
+ if selected_fee_nature in ["Fixed %", "Flat currency"]:
107
+ user_input = st.number_input("Please enter Commerical value:", min_value=0.0, help="Enter a valid number")
108
+ elif selected_fee_nature == "Slab based":
109
+ st.write("Please input values for the 3x3 table:")
110
+ table_data = [[st.number_input(f"Row {i+1}, Column {j+1}", value=0, step=1) for j in range(3)] for i in range(3)]
111
+ df = pd.DataFrame(table_data, columns=["Column 1", "Column 2", "Column 3"])
112
+ st.write(df)
113
+
114
+
115
+
116
+ # 6th layer: Expected Billing
117
+
118
+ Usage = st.number_input(f"Enter the usage limit for {selected_variable_type}", min_value=0.0, help="Enter the usage limit")
119
+ Capping_or_Minimum_Guarantee = st.number_input(f"Enter the Capping/Minimum Value for {selected_variable_type}", min_value = 0.0, help = "Enter the Capping/Minimum Gauarntee value")
120
+ Product = Usage*user_input if selected_fee_nature in ["Fixed %", "Flat currency"] else 0
121
+
122
+ abc = ['Capping value', 'Minimum Guarantee']
123
+ threshold = st.selectbox("Choose a threshold option:", ["--please select--"] + abc)
124
+
125
+ initial_expected_billing = Product
126
+
127
+ if threshold == 'Capping value':
128
+ expected_billing = Product if Capping_or_Minimum_Guarantee > Product else Capping_or_Minimum_Guarantee
129
+ elif threshold == 'Minimum Guarantee':
130
+ expected_billing = Product if Capping_or_Minimum_Guarantee < Product else Capping_or_Minimum_Guarantee
131
+ else:
132
+ expected_billing = initial_expected_billing # Default to initial Product value if no threshold selected
133
+
134
+ st.write(f"Expected Billing: {expected_billing}")
135
+
136
+
137
+ selected_plan_validity = st.selectbox("Plan Validity", ["--please select--"]+plan_validity_options, help="Select the plan validity")
138
+ selected_payment_method = st.selectbox("Payment Method",["--please select--"]+payment_method_options, help="Select the payment method")
139
+
140
+
141
+ # Submit button
142
+ if st.button("Submit"):
143
+ # Save user data
144
+ user_data = {
145
+ "Company ID": company_id,
146
+ "Company Name": company_name,
147
+ "Application ID": application_id,
148
+ "Fulfilling Location": fulfilling_location,
149
+ "Plan Name": plan_name,
150
+ "Plan Description": plan_description,
151
+ "Plan Start Date": plan_start_date,
152
+ "Ordering Channels": ordering_channels,
153
+ "Fee Type": selected_fee_type,
154
+ "Fee Nature": selected_fee_nature,
155
+ "Variable": selected_variable_type,
156
+ "Plan Validity": selected_plan_validity,
157
+ "Payment Method": selected_payment_method,
158
+ }
159
+ save_user_data(user_name, user_data)
160
+
161
+
162
+ # Display saved records
163
+ display_saved_records()