Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
|
@@ -14,14 +14,14 @@ from pyngrok import conf, ngrok
|
|
| 14 |
import requests
|
| 15 |
|
| 16 |
# Manually set ngrok path
|
| 17 |
-
|
| 18 |
|
| 19 |
# Set the ngrok path in the configuration
|
| 20 |
-
|
| 21 |
-
|
| 22 |
|
| 23 |
# Set your ngrok auth token
|
| 24 |
-
|
| 25 |
|
| 26 |
# logging.basicConfig(level=logging.INFO)
|
| 27 |
|
|
@@ -65,42 +65,40 @@ def save_slab_data(new_row):
|
|
| 65 |
# Function to generate PM_id
|
| 66 |
def generate_rule_id(user_data):
|
| 67 |
company_id = user_data.get('Company ID', '')
|
| 68 |
-
ordering_channels = user_data.get('
|
| 69 |
fulfilling_location = user_data.get('Fulfilling Location', '')
|
| 70 |
application_id = user_data.get('Application ID', '')
|
| 71 |
-
selected_fee_type =
|
| 72 |
-
selected_variable_type = user_data.get('Variable', '')
|
| 73 |
selected_chargeable_on = user_data.get('Chargeable on', '')
|
| 74 |
selected_fee_nature = user_data.get('Fee Nature', '')
|
| 75 |
threshold = user_data.get('Threshold option', '')
|
| 76 |
|
| 77 |
-
|
| 78 |
-
company_id = str(company_id) if company_id
|
| 79 |
-
ordering_channels = str(ordering_channels) if ordering_channels
|
| 80 |
-
fulfilling_location = str(fulfilling_location) if fulfilling_location
|
| 81 |
-
application_id = str(application_id) if application_id
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
# Extract first 2 characters from each field
|
| 91 |
rule_id_parts = [
|
| 92 |
-
company_id
|
| 93 |
-
ordering_channels
|
| 94 |
-
fulfilling_location
|
| 95 |
-
application_id
|
| 96 |
-
selected_fee_type
|
| 97 |
-
selected_variable_type
|
| 98 |
-
selected_chargeable_on
|
| 99 |
-
selected_fee_nature
|
| 100 |
-
threshold
|
| 101 |
]
|
| 102 |
|
| 103 |
-
rule_id = '_'.join(rule_id_parts) # Join parts with underscore
|
| 104 |
return rule_id
|
| 105 |
|
| 106 |
|
|
@@ -314,6 +312,7 @@ company_id_int = None
|
|
| 314 |
if company_id.strip():
|
| 315 |
try:
|
| 316 |
company_id_int = int(company_id.strip())
|
|
|
|
| 317 |
except ValueError:
|
| 318 |
st.error("Invalid Company ID. Please enter a valid integer.")
|
| 319 |
company_id_int = None
|
|
@@ -1092,31 +1091,32 @@ if bundle_by == "Feature specific":
|
|
| 1092 |
|
| 1093 |
rule_id = None
|
| 1094 |
plan_id = None
|
| 1095 |
-
business_head = st.session_state['business_head']
|
| 1096 |
company_name = st.session_state['company_name']
|
| 1097 |
company_id = st.session_state['company_id']
|
| 1098 |
-
currency = st.session_state['currency']
|
| 1099 |
-
# bundle_by = st.session_state['bundle_by']
|
| 1100 |
-
plan_name = st.session_state['plan_name']
|
| 1101 |
-
plan_description = st.session_state['plan_description']
|
| 1102 |
-
selected_ordering_channel = st.session_state['selected_ordering_channel']
|
| 1103 |
-
fulfilling_location = st.session_state['fulfilling_location']
|
| 1104 |
-
application_id = st.session_state['application_id']
|
| 1105 |
-
selected_fee_type = st.session_state['selected_fee_type']
|
| 1106 |
-
selected_variable_type = st.session_state['selected_variable_type']
|
| 1107 |
-
selected_chargeable_on = st.session_state['selected_chargeable_on']
|
| 1108 |
-
user_input_3 = st.session_state['user_input_3']
|
| 1109 |
-
usage_3 = st.session_state['usage_3']
|
| 1110 |
-
Capping_or_Minimum_Guarantee_3 = st.session_state['Capping_or_Minimum_Guarantee_3']
|
| 1111 |
-
fee_reversal = st.session_state['fee_reversal']
|
| 1112 |
-
reversal_per = st.session_state['reversal_per']
|
| 1113 |
-
threshold = st.session_state['threshold']
|
| 1114 |
-
expected_billing = st.session_state['expected_billing']
|
| 1115 |
-
selected_payment_method = st.session_state['selected_payment_method']
|
| 1116 |
-
selected_plan_validity = st.session_state['selected_plan_validity']
|
| 1117 |
-
final_billing = int(st.session_state['final_billing']) if st.session_state['final_billing'] is not None else 0
|
| 1118 |
|
| 1119 |
if st.button("Submit", key ='submit_button'):
|
|
|
|
| 1120 |
# Save user data
|
| 1121 |
user_data = {
|
| 1122 |
"Business_Head": business_head,
|
|
@@ -1145,21 +1145,27 @@ if bundle_by == "Feature specific":
|
|
| 1145 |
"Net_total_billing":int(final_billing)
|
| 1146 |
}
|
| 1147 |
|
| 1148 |
-
|
| 1149 |
-
|
| 1150 |
-
# Generate PM_id and add it to user_data
|
| 1151 |
rule_id = generate_rule_id(user_data)
|
| 1152 |
-
user_data['rule_id'] = rule_id
|
| 1153 |
-
|
| 1154 |
-
# Generate Plan ID and add it to user_data
|
| 1155 |
plan_id = generate_plan_id(user_data)
|
|
|
|
|
|
|
|
|
|
| 1156 |
user_data['plan_id'] = plan_id
|
| 1157 |
|
| 1158 |
-
|
|
|
|
|
|
|
| 1159 |
|
| 1160 |
-
|
| 1161 |
display_saved_records()
|
| 1162 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1163 |
|
| 1164 |
if st.button("Export data to BQ"):
|
| 1165 |
def insert_into_bq(user_data, project_id, dataset_id, table_id, service_account_info):
|
|
@@ -1197,7 +1203,11 @@ if bundle_by == "Feature specific":
|
|
| 1197 |
application_id = st.session_state['application_id']
|
| 1198 |
# bundle_by = st.session_state['bundle_by']
|
| 1199 |
|
| 1200 |
-
created_at
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1201 |
|
| 1202 |
user_data = {
|
| 1203 |
"Business_Head": business_head,
|
|
@@ -1229,15 +1239,6 @@ if bundle_by == "Feature specific":
|
|
| 1229 |
"Net_total_billing":int(final_billing)
|
| 1230 |
}
|
| 1231 |
|
| 1232 |
-
global_user_data.append((user_name, user_data))
|
| 1233 |
-
|
| 1234 |
-
# Generate PM_id and add it to user_data
|
| 1235 |
-
rule_id = generate_rule_id(user_data)
|
| 1236 |
-
user_data['rule_id'] = rule_id
|
| 1237 |
-
|
| 1238 |
-
# Generate Plan ID and add it to user_data
|
| 1239 |
-
plan_id = generate_plan_id(user_data)
|
| 1240 |
-
user_data['plan_id'] = plan_id
|
| 1241 |
|
| 1242 |
save_user_data(user_data) # Save user data after submission
|
| 1243 |
|
|
@@ -1263,7 +1264,7 @@ if bundle_by == "Feature specific":
|
|
| 1263 |
elif bundle_by == "Single value":
|
| 1264 |
user_input_1 = st.sidebar.number_input("Enter Commercial value:")
|
| 1265 |
user_input_2 = float(user_input_1)
|
| 1266 |
-
user_input_3 = "{:.2f}".format(user_input_2)
|
| 1267 |
|
| 1268 |
plan_name = st.sidebar.text_input("Plan Name", help="Enter the name of the plan")
|
| 1269 |
plan_description = st.sidebar.text_area("Plan Description", max_chars=250, help="Describe the plan")
|
|
@@ -1838,16 +1839,18 @@ elif bundle_by == "Single value":
|
|
| 1838 |
selected_payment_method = st.selectbox("Payment Method", [""] + payment_method_options, help="Payment method defines the mode of payment of the plan", key="py_vd_2")
|
| 1839 |
|
| 1840 |
initial_net_billing = 0
|
| 1841 |
-
|
| 1842 |
|
| 1843 |
-
if selected_plan_validity == 'One time'
|
| 1844 |
-
final_billing = 1*expected_billing
|
|
|
|
|
|
|
| 1845 |
elif selected_plan_validity == 'Quarterly':
|
| 1846 |
-
final_billing = 3*expected_billing
|
| 1847 |
elif selected_plan_validity == 'Bi-Annually':
|
| 1848 |
-
final_billing = 6*expected_billing
|
| 1849 |
elif selected_plan_validity == 'Annually':
|
| 1850 |
-
final_billing = 12*expected_billing
|
| 1851 |
else:
|
| 1852 |
final_billing = initial_net_billing
|
| 1853 |
|
|
@@ -1892,31 +1895,30 @@ elif bundle_by == "Single value":
|
|
| 1892 |
|
| 1893 |
rule_id = None
|
| 1894 |
plan_id = None
|
| 1895 |
-
business_head = st.session_state['business_head']
|
| 1896 |
company_name = st.session_state['company_name']
|
| 1897 |
company_id = st.session_state['company_id']
|
| 1898 |
-
currency = st.session_state['currency']
|
| 1899 |
-
# bundle_by = st.session_state['bundle_by']
|
| 1900 |
-
plan_name = st.session_state['plan_name']
|
| 1901 |
-
plan_description = st.session_state['plan_description']
|
| 1902 |
-
selected_ordering_channel = st.session_state['selected_ordering_channel']
|
| 1903 |
-
fulfilling_location = st.session_state['fulfilling_location']
|
| 1904 |
-
application_id = st.session_state['application_id']
|
| 1905 |
-
selected_fee_type = st.session_state['selected_fee_type']
|
| 1906 |
-
selected_variable_type = st.session_state['selected_variable_type']
|
| 1907 |
-
selected_chargeable_on = st.session_state['selected_chargeable_on']
|
| 1908 |
-
user_input_3 = st.session_state['user_input_3']
|
| 1909 |
-
usage_3 = st.session_state['usage_3']
|
| 1910 |
-
Capping_or_Minimum_Guarantee_3 = st.session_state['Capping_or_Minimum_Guarantee_3']
|
| 1911 |
-
fee_reversal = st.session_state['fee_reversal']
|
| 1912 |
-
reversal_per = st.session_state['reversal_per']
|
| 1913 |
-
threshold = st.session_state['threshold']
|
| 1914 |
-
expected_billing = st.session_state['expected_billing']
|
| 1915 |
-
selected_payment_method = st.session_state['selected_payment_method']
|
| 1916 |
-
selected_plan_validity = st.session_state['selected_plan_validity']
|
| 1917 |
-
final_billing = int(st.session_state['final_billing']) if st.session_state['final_billing'] is not None else 0
|
| 1918 |
-
|
| 1919 |
-
|
| 1920 |
|
| 1921 |
# Submit button
|
| 1922 |
if st.button("Submit"):
|
|
@@ -1935,7 +1937,7 @@ elif bundle_by == "Single value":
|
|
| 1935 |
"Fee Type": selected_fee_type,
|
| 1936 |
"Variable Type": selected_variable_type,
|
| 1937 |
"Chargeable on": selected_chargeable_on,
|
| 1938 |
-
"Fee Nature":
|
| 1939 |
"Commercial value": user_input_3,
|
| 1940 |
"Fee reversal": 0,
|
| 1941 |
"Reversal %": 0,
|
|
@@ -1948,23 +1950,28 @@ elif bundle_by == "Single value":
|
|
| 1948 |
"Net_total_billing":int(final_billing)
|
| 1949 |
}
|
| 1950 |
|
| 1951 |
-
|
| 1952 |
-
|
| 1953 |
-
# Generate PM_id and add it to user_data
|
| 1954 |
rule_id = generate_rule_id(user_data)
|
| 1955 |
-
user_data['rule_id'] = rule_id
|
| 1956 |
-
|
| 1957 |
-
# Generate Plan ID and add it to user_data
|
| 1958 |
plan_id = generate_plan_id(user_data)
|
| 1959 |
-
user_data['plan_id'] = plan_id
|
| 1960 |
|
|
|
|
|
|
|
|
|
|
| 1961 |
|
| 1962 |
-
|
|
|
|
|
|
|
| 1963 |
|
| 1964 |
-
|
| 1965 |
display_saved_records()
|
| 1966 |
|
| 1967 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1968 |
|
| 1969 |
if st.button("Export data to BQ"):
|
| 1970 |
|
|
@@ -2000,8 +2007,7 @@ elif bundle_by == "Single value":
|
|
| 2000 |
logging.exception("An error occurred during the BigQuery insert operation.")
|
| 2001 |
st.error(f"An error occurred: {e}")
|
| 2002 |
|
| 2003 |
-
|
| 2004 |
-
|
| 2005 |
|
| 2006 |
project_id = "fynd-db"
|
| 2007 |
dataset_id = "finance_dwh"
|
|
@@ -2010,10 +2016,13 @@ elif bundle_by == "Single value":
|
|
| 2010 |
application_id = st.session_state['application_id']
|
| 2011 |
# bundle_by = st.session_state['bundle_by']
|
| 2012 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2013 |
|
| 2014 |
-
|
| 2015 |
-
|
| 2016 |
-
|
| 2017 |
user_data = {
|
| 2018 |
"Business_Head": business_head,
|
| 2019 |
"Company_ID": company_id if company_id and company_id.strip() else None,
|
|
@@ -2028,7 +2037,7 @@ elif bundle_by == "Single value":
|
|
| 2028 |
"Fee_Type": selected_fee_type,
|
| 2029 |
"Variable_Type": selected_variable_type,
|
| 2030 |
"Chargeable_on": selected_chargeable_on,
|
| 2031 |
-
"Fee_Nature":
|
| 2032 |
"Commercial_value": user_input_3,
|
| 2033 |
"Fee_reversal": 0,
|
| 2034 |
"Reversal_%": 0,
|
|
@@ -2041,19 +2050,9 @@ elif bundle_by == "Single value":
|
|
| 2041 |
"rule_id": rule_id,
|
| 2042 |
"plan_id": plan_id,
|
| 2043 |
"created_at": created_at,
|
| 2044 |
-
"Net_total_billing":int(final_billing)
|
| 2045 |
}
|
| 2046 |
-
|
| 2047 |
-
global_user_data.append((user_name, user_data))
|
| 2048 |
-
|
| 2049 |
-
# Generate PM_id and add it to user_data
|
| 2050 |
-
rule_id = generate_rule_id(user_data)
|
| 2051 |
-
user_data['rule_id'] = rule_id
|
| 2052 |
-
|
| 2053 |
-
# Generate Plan ID and add it to user_data
|
| 2054 |
-
plan_id = generate_plan_id(user_data)
|
| 2055 |
-
user_data['plan_id'] = plan_id
|
| 2056 |
-
|
| 2057 |
|
| 2058 |
save_user_data(user_data)
|
| 2059 |
|
|
@@ -2107,8 +2106,8 @@ st.write(" ")
|
|
| 2107 |
# Start a tunnel to the correct port
|
| 2108 |
|
| 2109 |
# Connect to a port (e.g., 8501) without a custom subdomain
|
| 2110 |
-
|
| 2111 |
-
|
| 2112 |
-
|
| 2113 |
-
|
| 2114 |
-
|
|
|
|
| 14 |
import requests
|
| 15 |
|
| 16 |
# Manually set ngrok path
|
| 17 |
+
ngrok_path = "/Users/ninadmandavkar/Desktop/ngrok/ngrok 3"
|
| 18 |
|
| 19 |
# Set the ngrok path in the configuration
|
| 20 |
+
config = conf.get_default()
|
| 21 |
+
config.ngrok_path = ngrok_path
|
| 22 |
|
| 23 |
# Set your ngrok auth token
|
| 24 |
+
ngrok.set_auth_token('2jQ6LRMBFqe25TP7o2ugti9EH6Y_3mBzBYbsjZmhh69eGq2Q1')
|
| 25 |
|
| 26 |
# logging.basicConfig(level=logging.INFO)
|
| 27 |
|
|
|
|
| 65 |
# Function to generate PM_id
|
| 66 |
def generate_rule_id(user_data):
|
| 67 |
company_id = user_data.get('Company ID', '')
|
| 68 |
+
ordering_channels = user_data.get('Product lines', '')
|
| 69 |
fulfilling_location = user_data.get('Fulfilling Location', '')
|
| 70 |
application_id = user_data.get('Application ID', '')
|
| 71 |
+
selected_fee_type = user_data.get('Fee Type', '')
|
| 72 |
+
selected_variable_type = user_data.get('Variable Type', '')
|
| 73 |
selected_chargeable_on = user_data.get('Chargeable on', '')
|
| 74 |
selected_fee_nature = user_data.get('Fee Nature', '')
|
| 75 |
threshold = user_data.get('Threshold option', '')
|
| 76 |
|
| 77 |
+
# Ensure all fields are strings and handle None or empty values
|
| 78 |
+
company_id = str(company_id).zfill(5)[:5] if company_id else '00000'
|
| 79 |
+
ordering_channels = str(ordering_channels)[:2] if ordering_channels else '00'
|
| 80 |
+
fulfilling_location = str(fulfilling_location)[:2] if fulfilling_location else '00'
|
| 81 |
+
application_id = str(application_id)[:2] if application_id else '00'
|
| 82 |
+
selected_fee_type = str(selected_fee_type)[:2] if selected_fee_type else '00'
|
| 83 |
+
selected_variable_type = str(selected_variable_type)[:2] if selected_variable_type else '00'
|
| 84 |
+
selected_chargeable_on = str(selected_chargeable_on)[:2] if selected_chargeable_on else '00'
|
| 85 |
+
selected_fee_nature = str(selected_fee_nature)[:2] if selected_fee_nature else '00'
|
| 86 |
+
threshold = str(threshold)[:2] if threshold else '00'
|
| 87 |
+
|
| 88 |
+
# Extract first 2 characters from each field and ensure proper length
|
|
|
|
|
|
|
| 89 |
rule_id_parts = [
|
| 90 |
+
company_id, # Ensure 5 characters
|
| 91 |
+
ordering_channels, # Ensure 2 characters
|
| 92 |
+
fulfilling_location, # Ensure 2 characters
|
| 93 |
+
application_id, # Ensure 2 characters
|
| 94 |
+
selected_fee_type, # Ensure 2 characters
|
| 95 |
+
selected_variable_type, # Ensure 2 characters
|
| 96 |
+
selected_chargeable_on, # Ensure 2 characters
|
| 97 |
+
selected_fee_nature, # Ensure 2 characters
|
| 98 |
+
threshold # Ensure 2 characters
|
| 99 |
]
|
| 100 |
|
| 101 |
+
rule_id = '_'.join(rule_id_parts) # Join parts with an underscore
|
| 102 |
return rule_id
|
| 103 |
|
| 104 |
|
|
|
|
| 312 |
if company_id.strip():
|
| 313 |
try:
|
| 314 |
company_id_int = int(company_id.strip())
|
| 315 |
+
st.session_state['company_id'] = company_id.strip() #ALways store the company id in session state
|
| 316 |
except ValueError:
|
| 317 |
st.error("Invalid Company ID. Please enter a valid integer.")
|
| 318 |
company_id_int = None
|
|
|
|
| 1091 |
|
| 1092 |
rule_id = None
|
| 1093 |
plan_id = None
|
| 1094 |
+
# business_head = st.session_state['business_head']
|
| 1095 |
company_name = st.session_state['company_name']
|
| 1096 |
company_id = st.session_state['company_id']
|
| 1097 |
+
# currency = st.session_state['currency']
|
| 1098 |
+
# # bundle_by = st.session_state['bundle_by']
|
| 1099 |
+
# plan_name = st.session_state['plan_name']
|
| 1100 |
+
# plan_description = st.session_state['plan_description']
|
| 1101 |
+
# selected_ordering_channel = st.session_state['selected_ordering_channel']
|
| 1102 |
+
# fulfilling_location = st.session_state['fulfilling_location']
|
| 1103 |
+
# application_id = st.session_state['application_id']
|
| 1104 |
+
# selected_fee_type = st.session_state['selected_fee_type']
|
| 1105 |
+
# selected_variable_type = st.session_state['selected_variable_type']
|
| 1106 |
+
# selected_chargeable_on = st.session_state['selected_chargeable_on']
|
| 1107 |
+
# user_input_3 = st.session_state['user_input_3']
|
| 1108 |
+
# usage_3 = st.session_state['usage_3']
|
| 1109 |
+
# Capping_or_Minimum_Guarantee_3 = st.session_state['Capping_or_Minimum_Guarantee_3']
|
| 1110 |
+
# fee_reversal = st.session_state['fee_reversal']
|
| 1111 |
+
# reversal_per = st.session_state['reversal_per']
|
| 1112 |
+
# threshold = st.session_state['threshold']
|
| 1113 |
+
# expected_billing = st.session_state['expected_billing']
|
| 1114 |
+
# selected_payment_method = st.session_state['selected_payment_method']
|
| 1115 |
+
# selected_plan_validity = st.session_state['selected_plan_validity']
|
| 1116 |
+
# final_billing = int(st.session_state['final_billing']) if st.session_state['final_billing'] is not None else 0
|
| 1117 |
|
| 1118 |
if st.button("Submit", key ='submit_button'):
|
| 1119 |
+
|
| 1120 |
# Save user data
|
| 1121 |
user_data = {
|
| 1122 |
"Business_Head": business_head,
|
|
|
|
| 1145 |
"Net_total_billing":int(final_billing)
|
| 1146 |
}
|
| 1147 |
|
| 1148 |
+
# Generate rule_id and plan_id
|
|
|
|
|
|
|
| 1149 |
rule_id = generate_rule_id(user_data)
|
|
|
|
|
|
|
|
|
|
| 1150 |
plan_id = generate_plan_id(user_data)
|
| 1151 |
+
|
| 1152 |
+
# Update user_data with generated IDs
|
| 1153 |
+
user_data['rule_id'] = rule_id
|
| 1154 |
user_data['plan_id'] = plan_id
|
| 1155 |
|
| 1156 |
+
# Save the user data locally and to session state
|
| 1157 |
+
global_user_data.append((user_name, user_data))
|
| 1158 |
+
save_user_data(user_data)
|
| 1159 |
|
| 1160 |
+
# Display saved records
|
| 1161 |
display_saved_records()
|
| 1162 |
|
| 1163 |
+
|
| 1164 |
+
# Store created_at, rule_id, and plan_id in session state
|
| 1165 |
+
st.session_state['created_at'] = datetime.now().isoformat()
|
| 1166 |
+
st.session_state['rule_id'] = rule_id
|
| 1167 |
+
st.session_state['plan_id'] = plan_id
|
| 1168 |
+
|
| 1169 |
|
| 1170 |
if st.button("Export data to BQ"):
|
| 1171 |
def insert_into_bq(user_data, project_id, dataset_id, table_id, service_account_info):
|
|
|
|
| 1203 |
application_id = st.session_state['application_id']
|
| 1204 |
# bundle_by = st.session_state['bundle_by']
|
| 1205 |
|
| 1206 |
+
# Retrieve created_at, rule_id, and plan_id from session state
|
| 1207 |
+
created_at = st.session_state.get('created_at')
|
| 1208 |
+
rule_id = st.session_state.get('rule_id')
|
| 1209 |
+
plan_id = st.session_state.get('plan_id')
|
| 1210 |
+
|
| 1211 |
|
| 1212 |
user_data = {
|
| 1213 |
"Business_Head": business_head,
|
|
|
|
| 1239 |
"Net_total_billing":int(final_billing)
|
| 1240 |
}
|
| 1241 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1242 |
|
| 1243 |
save_user_data(user_data) # Save user data after submission
|
| 1244 |
|
|
|
|
| 1264 |
elif bundle_by == "Single value":
|
| 1265 |
user_input_1 = st.sidebar.number_input("Enter Commercial value:")
|
| 1266 |
user_input_2 = float(user_input_1)
|
| 1267 |
+
st.session_state['user_input_3'] = "{:.2f}".format(user_input_2)
|
| 1268 |
|
| 1269 |
plan_name = st.sidebar.text_input("Plan Name", help="Enter the name of the plan")
|
| 1270 |
plan_description = st.sidebar.text_area("Plan Description", max_chars=250, help="Describe the plan")
|
|
|
|
| 1839 |
selected_payment_method = st.selectbox("Payment Method", [""] + payment_method_options, help="Payment method defines the mode of payment of the plan", key="py_vd_2")
|
| 1840 |
|
| 1841 |
initial_net_billing = 0
|
| 1842 |
+
user_input_3 = st.session_state['user_input_3']
|
| 1843 |
|
| 1844 |
+
if selected_plan_validity == 'One time':
|
| 1845 |
+
final_billing = 1 * expected_billing
|
| 1846 |
+
elif selected_plan_validity == 'Monthly':
|
| 1847 |
+
final_billing = 1 * expected_billing
|
| 1848 |
elif selected_plan_validity == 'Quarterly':
|
| 1849 |
+
final_billing = 3 * expected_billing
|
| 1850 |
elif selected_plan_validity == 'Bi-Annually':
|
| 1851 |
+
final_billing = 6 * expected_billing
|
| 1852 |
elif selected_plan_validity == 'Annually':
|
| 1853 |
+
final_billing = 12 * expected_billing
|
| 1854 |
else:
|
| 1855 |
final_billing = initial_net_billing
|
| 1856 |
|
|
|
|
| 1895 |
|
| 1896 |
rule_id = None
|
| 1897 |
plan_id = None
|
| 1898 |
+
# business_head = st.session_state['business_head']
|
| 1899 |
company_name = st.session_state['company_name']
|
| 1900 |
company_id = st.session_state['company_id']
|
| 1901 |
+
# currency = st.session_state['currency']
|
| 1902 |
+
# # bundle_by = st.session_state['bundle_by']
|
| 1903 |
+
# plan_name = st.session_state['plan_name']
|
| 1904 |
+
# plan_description = st.session_state['plan_description']
|
| 1905 |
+
# selected_ordering_channel = st.session_state['selected_ordering_channel']
|
| 1906 |
+
# fulfilling_location = st.session_state['fulfilling_location']
|
| 1907 |
+
# application_id = st.session_state['application_id']
|
| 1908 |
+
# selected_fee_type = st.session_state['selected_fee_type']
|
| 1909 |
+
# selected_variable_type = st.session_state['selected_variable_type']
|
| 1910 |
+
# selected_chargeable_on = st.session_state['selected_chargeable_on']
|
| 1911 |
+
# user_input_3 = st.session_state['user_input_3']
|
| 1912 |
+
# usage_3 = st.session_state['usage_3']
|
| 1913 |
+
# Capping_or_Minimum_Guarantee_3 = st.session_state['Capping_or_Minimum_Guarantee_3']
|
| 1914 |
+
# fee_reversal = st.session_state['fee_reversal']
|
| 1915 |
+
# reversal_per = st.session_state['reversal_per']
|
| 1916 |
+
# threshold = st.session_state['threshold']
|
| 1917 |
+
# expected_billing = st.session_state['expected_billing']
|
| 1918 |
+
# selected_payment_method = st.session_state['selected_payment_method']
|
| 1919 |
+
# selected_plan_validity = st.session_state['selected_plan_validity']
|
| 1920 |
+
# final_billing = int(st.session_state['final_billing']) if st.session_state['final_billing'] is not None else 0
|
| 1921 |
+
|
|
|
|
| 1922 |
|
| 1923 |
# Submit button
|
| 1924 |
if st.button("Submit"):
|
|
|
|
| 1937 |
"Fee Type": selected_fee_type,
|
| 1938 |
"Variable Type": selected_variable_type,
|
| 1939 |
"Chargeable on": selected_chargeable_on,
|
| 1940 |
+
"Fee Nature": 0,
|
| 1941 |
"Commercial value": user_input_3,
|
| 1942 |
"Fee reversal": 0,
|
| 1943 |
"Reversal %": 0,
|
|
|
|
| 1950 |
"Net_total_billing":int(final_billing)
|
| 1951 |
}
|
| 1952 |
|
| 1953 |
+
|
| 1954 |
+
# Generate rule_id and plan_id
|
|
|
|
| 1955 |
rule_id = generate_rule_id(user_data)
|
|
|
|
|
|
|
|
|
|
| 1956 |
plan_id = generate_plan_id(user_data)
|
|
|
|
| 1957 |
|
| 1958 |
+
# Update user_data with generated IDs
|
| 1959 |
+
user_data['rule_id'] = rule_id
|
| 1960 |
+
user_data['plan_id'] = plan_id
|
| 1961 |
|
| 1962 |
+
# Save the user data locally and to session state
|
| 1963 |
+
global_user_data.append((user_name, user_data))
|
| 1964 |
+
save_user_data(user_data)
|
| 1965 |
|
| 1966 |
+
# Display saved records
|
| 1967 |
display_saved_records()
|
| 1968 |
|
| 1969 |
|
| 1970 |
+
# Store created_at, rule_id, and plan_id in session state
|
| 1971 |
+
st.session_state['created_at'] = datetime.now().isoformat()
|
| 1972 |
+
st.session_state['rule_id'] = rule_id
|
| 1973 |
+
st.session_state['plan_id'] = plan_id
|
| 1974 |
+
|
| 1975 |
|
| 1976 |
if st.button("Export data to BQ"):
|
| 1977 |
|
|
|
|
| 2007 |
logging.exception("An error occurred during the BigQuery insert operation.")
|
| 2008 |
st.error(f"An error occurred: {e}")
|
| 2009 |
|
| 2010 |
+
|
|
|
|
| 2011 |
|
| 2012 |
project_id = "fynd-db"
|
| 2013 |
dataset_id = "finance_dwh"
|
|
|
|
| 2016 |
application_id = st.session_state['application_id']
|
| 2017 |
# bundle_by = st.session_state['bundle_by']
|
| 2018 |
|
| 2019 |
+
|
| 2020 |
+
# Retrieve created_at, rule_id, and plan_id from session state
|
| 2021 |
+
created_at = st.session_state.get('created_at')
|
| 2022 |
+
rule_id = st.session_state.get('rule_id')
|
| 2023 |
+
plan_id = st.session_state.get('plan_id')
|
| 2024 |
|
| 2025 |
+
# Prepare user_data for BigQuery with correct rule_id and plan_id
|
|
|
|
|
|
|
| 2026 |
user_data = {
|
| 2027 |
"Business_Head": business_head,
|
| 2028 |
"Company_ID": company_id if company_id and company_id.strip() else None,
|
|
|
|
| 2037 |
"Fee_Type": selected_fee_type,
|
| 2038 |
"Variable_Type": selected_variable_type,
|
| 2039 |
"Chargeable_on": selected_chargeable_on,
|
| 2040 |
+
"Fee_Nature": 0,
|
| 2041 |
"Commercial_value": user_input_3,
|
| 2042 |
"Fee_reversal": 0,
|
| 2043 |
"Reversal_%": 0,
|
|
|
|
| 2050 |
"rule_id": rule_id,
|
| 2051 |
"plan_id": plan_id,
|
| 2052 |
"created_at": created_at,
|
| 2053 |
+
"Net_total_billing": int(final_billing)
|
| 2054 |
}
|
| 2055 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2056 |
|
| 2057 |
save_user_data(user_data)
|
| 2058 |
|
|
|
|
| 2106 |
# Start a tunnel to the correct port
|
| 2107 |
|
| 2108 |
# Connect to a port (e.g., 8501) without a custom subdomain
|
| 2109 |
+
try:
|
| 2110 |
+
ngrok_tunnel = ngrok.connect(8501) # Replace 8501 with your port number
|
| 2111 |
+
print(f"ngrok tunnel URL: {ngrok_tunnel.public_url}")
|
| 2112 |
+
except Exception as e:
|
| 2113 |
+
print(f"Failed to start ngrok tunnel: {e}")
|