Ninad077 commited on
Commit
4d83a43
·
verified ·
1 Parent(s): 166a36f

Upload 2 files

Browse files
Files changed (2) hide show
  1. query_seller_sale.py +77 -33
  2. seller.py +105 -31
query_seller_sale.py CHANGED
@@ -1,16 +1,9 @@
1
- # query_seller_sale.py
 
2
  queries = {
3
  "query": """
4
- select
5
- *,
6
- (seller_sale_cc - tds_cc - tcs_cc) as seller_net_cc,
7
- round((seller_sale_cc - tds_cc - tcs_cc - seller_net_collection),2) as net_diff_cc,
8
- Concat(bag_id,",")as conccat,
9
- COUNT(bag_cc) as comment,
10
- concat(company_id,'_',segement_code, '_', settlement_model_code, '_', order_type) as ledger_name
11
- from
12
- (
13
- select
14
  company_id,
15
  company_name,
16
  ordering_channel,
@@ -19,40 +12,91 @@ queries = {
19
  settlement_model,
20
  settlement_model_code,
21
  order_type,
22
- recon_status,
23
- fiscal_Year,
24
  bag_id,
25
  settlement_type,
26
- Concat(bag_id,settlement_type) as bag_cc ,
 
 
 
 
 
27
  mrp,
28
  seller_discounts,
29
  store_discount_amount,
30
  bca,
31
- vog,
 
32
  tds_on_bca,
33
  tcs_on_vog,
34
  seller_fees,
35
  seller_tender_value,
36
- seller_net_collection,
37
- mrp - seller_discounts -store_discount_amount as bca_cc,
38
- bca - (mrp - seller_discounts -store_discount_amount) as diff_bca_cc,
39
- round((mrp - seller_discounts -store_discount_amount)*100/(100 +product_gst_perc),2) as vog_cc,
40
- vog - (round((mrp - seller_discounts -store_discount_amount)*100/(100 +product_gst_perc),2)) as diff_vog_cc,
 
 
41
  CASE
42
- WHEN segement_code = 'FY' or segement_code = 'UN' THEN (mrp - seller_discounts -store_discount_amount)*0.01
43
- ELSE 0
44
- END as tds_cc,
 
 
 
 
 
45
  CASE
46
- WHEN segement_code = 'FY' or segement_code = 'UN' THEN (round((mrp - seller_discounts -store_discount_amount)*100/(100 +product_gst_perc),2))*0.005
47
- ELSE 0
48
- END as tcs_cc,
49
- (mrp - seller_discounts -store_discount_amount - seller_tender_value + seller_fees) as seller_sale_cc
50
- from
 
 
51
  `fynd-db.finance_recon_tool_asia.09_seller_net_collection_daily`
52
- where
53
- expected_payout_date between "2024-09-03"
54
- and "2024-09-09"
55
- ) as A
56
- group by all
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
  """
58
  }
 
1
+ # query_seller_sale.py\
2
+
3
  queries = {
4
  "query": """
5
+ WITH seller_net_data AS (
6
+ SELECT
 
 
 
 
 
 
 
 
7
  company_id,
8
  company_name,
9
  ordering_channel,
 
12
  settlement_model,
13
  settlement_model_code,
14
  order_type,
15
+ order_date,
16
+ fiscal_year,
17
  bag_id,
18
  settlement_type,
19
+ recon_status,
20
+ return_window_date,
21
+ payout_window_date,
22
+ expected_payout_date,
23
+ sett_no,
24
+ sett_id,
25
  mrp,
26
  seller_discounts,
27
  store_discount_amount,
28
  bca,
29
+ product_gst_perc,
30
+ round(vog,2) as vog,
31
  tds_on_bca,
32
  tcs_on_vog,
33
  seller_fees,
34
  seller_tender_value,
35
+ round(seller_net_collection,2) as seller_net_collection,
36
+ ROUND(mrp - seller_discounts - store_discount_amount,2) AS bca_cc,
37
+ ROUND(bca - (mrp - seller_discounts - store_discount_amount),2) AS diff_bca_cc,
38
+ ROUND((mrp - seller_discounts - store_discount_amount) * 100 / (100 + ABS(product_gst_perc)), 2) AS vog_cc,
39
+ ROUND(vog - ROUND((mrp - seller_discounts - store_discount_amount) * 100 / (100 + ABS(product_gst_perc)), 2),2) AS diff_vog_cc,
40
+
41
+ -- TDS calculation logic
42
  CASE
43
+ WHEN segement_code IN ("FY", "UN") AND DATE(order_date) >= '2024-10-01' THEN
44
+ ROUND((mrp - seller_discounts - store_discount_amount), 2) * 0.001
45
+ WHEN segement_code IN ("FY", "UN") AND DATE(order_date) < '2024-10-01' THEN
46
+ ROUND((mrp - seller_discounts - store_discount_amount), 2) * 0.01
47
+ ELSE 0
48
+ END AS tds_cc,
49
+
50
+ -- TCS calculation logic
51
  CASE
52
+ WHEN segement_code IN ("FY", "UN") AND DATE(order_date) >= '2024-07-10' THEN
53
+ ROUND((mrp - seller_discounts - store_discount_amount) * 100 / (100 + ABS(product_gst_perc)), 2) * 0.005
54
+ WHEN segement_code IN ("FY", "UN") AND DATE(order_date) < '2024-07-10' THEN
55
+ ROUND((mrp - seller_discounts - store_discount_amount) * 100 / (100 + ABS(product_gst_perc)), 2) * 0.01
56
+ ELSE 0
57
+ END AS tcs_cc
58
+ FROM
59
  `fynd-db.finance_recon_tool_asia.09_seller_net_collection_daily`
60
+ WHERE
61
+ expected_payout_date BETWEEN "{start_date}" AND "{end_date}"
62
+ ),
63
+
64
+ -- Subquery to count occurrences of each bag_id and concatenation of bag_id and settlement_type
65
+ bag_con_count_data AS (
66
+ SELECT
67
+ bag_id,
68
+ settlement_type,
69
+ COUNT(*) AS bagg_count,
70
+ CONCAT(bag_id, settlement_type) AS bag_settlement_concat,
71
+ COUNT(CONCAT(bag_id, settlement_type)) AS bag_settlement_concat_count -- Count of concatenated values
72
+ FROM
73
+ seller_net_data
74
+ GROUP BY
75
+ bag_id, settlement_type
76
+ )
77
+
78
+ -- Final query
79
+ SELECT
80
+ sd.*,
81
+ ROUND((tds_cc - tds_on_bca), 2) AS diff_tds,
82
+ ROUND((tcs_cc - tcs_on_vog), 2) AS diff_tcs,
83
+ ROUND((mrp - seller_discounts - store_discount_amount - seller_tender_value + seller_fees),2) AS seller_sale_cc,
84
+ ROUND(((mrp - seller_discounts - store_discount_amount - seller_tender_value + seller_fees) - tds_cc - tcs_cc),2) AS seller_net_cc,
85
+ ROUND(((mrp - seller_discounts - store_discount_amount - seller_tender_value + seller_fees) - tds_cc - tcs_cc - seller_net_collection), 2) AS net_diff_cc,
86
+ CONCAT(sd.bag_id, ",") AS conccat, -- Concatenated bag_id
87
+ CONCAT(sd.bag_id, sd.settlement_type) AS bag_cc, -- Bag ID with settlement type
88
+ bcc.bagg_count AS bag_count, -- Count of each bag_id and settlement type
89
+ bcc.bag_settlement_concat AS bag_con, -- Concatenated bag_id and settlement_type
90
+ bcc.bag_settlement_concat_count AS bag_con_count, -- Count of concatenated values
91
+ CASE
92
+ WHEN order_type = 'COD' THEN CONCAT(company_id, '_', segement_code, '_', settlement_model_code, '_', order_type, '_V')
93
+ WHEN order_type = 'PPD' THEN CONCAT(company_id, '_', segement_code, '_', settlement_model_code, '_', order_type, '_C')
94
+ END AS ledger_name
95
+ FROM
96
+ seller_net_data sd
97
+ LEFT JOIN
98
+ bag_con_count_data bcc
99
+ ON
100
+ sd.bag_id = bcc.bag_id AND sd.settlement_type = bcc.settlement_type;
101
  """
102
  }
seller.py CHANGED
@@ -68,13 +68,14 @@ html_subject = """
68
  st.markdown(html_subject, unsafe_allow_html=True)
69
  # selection = st.multiselect("", webhook_url)
70
 
 
71
  def check_duplicates(credentials_file):
72
  """Check for duplicates using BigQuery with the provided credentials file."""
73
  results = {}
74
  credentials = service_account.Credentials.from_service_account_info(json.loads(credentials_file))
75
  client = bigquery.Client(credentials=credentials, project=credentials.project_id)
76
 
77
- query = queries["query"] # Access the query string from the dictionary
78
 
79
  # Show a loading spinner
80
  with st.spinner(":red[Performing seller sale validation...]"):
@@ -166,39 +167,112 @@ html_subject = """
166
 
167
  st.markdown(html_subject, unsafe_allow_html=True)
168
 
 
 
169
  # Upload credentials file
170
  credentials_file = st.file_uploader("", type="json")
171
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
172
  if credentials_file is not None:
173
- # Read the credentials file
174
- credentials_data = credentials_file.read().decode("utf-8")
175
-
176
- # Check for duplicates
177
- results = check_duplicates(credentials_data)
178
-
179
- if "Query Result" in results:
180
- df = results["Query Result"]
181
 
182
- # Download buttons
183
- csv = df.to_csv(index=False)
184
- excel = io.BytesIO()
185
- with pd.ExcelWriter(excel, engine='openpyxl') as writer:
186
- df.to_excel(writer, index=False)
187
- excel.seek(0)
188
 
189
- col1, col2 = st.columns([0.125, 0.5])
190
- with col1:
191
- st.download_button(
192
- label=":red[Download CSV]",
193
- data=csv,
194
- file_name="seller_sale_recon.csv",
195
- mime="text/csv"
196
- )
197
-
198
- with col2:
199
- st.download_button(
200
- label=":red[Download Excel]",
201
- data=excel,
202
- file_name="seller_sale_recon.xlsx",
203
- mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
204
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
  st.markdown(html_subject, unsafe_allow_html=True)
69
  # selection = st.multiselect("", webhook_url)
70
 
71
+
72
  def check_duplicates(credentials_file):
73
  """Check for duplicates using BigQuery with the provided credentials file."""
74
  results = {}
75
  credentials = service_account.Credentials.from_service_account_info(json.loads(credentials_file))
76
  client = bigquery.Client(credentials=credentials, project=credentials.project_id)
77
 
78
+ query = queries["query"].format(start_date = start_date_str, end_date = end_date_str) # Access the query string from the dictionary
79
 
80
  # Show a loading spinner
81
  with st.spinner(":red[Performing seller sale validation...]"):
 
167
 
168
  st.markdown(html_subject, unsafe_allow_html=True)
169
 
170
+
171
+
172
  # Upload credentials file
173
  credentials_file = st.file_uploader("", type="json")
174
 
175
+
176
+
177
+ html_subject = """
178
+ <html>
179
+ <head>
180
+ <style>
181
+ .button {
182
+ display: inline-block;
183
+ padding: 10px 20px;
184
+ border-radius: 12px;
185
+ background: linear-gradient(to bottom, #f8f9fa, #e0e0e0);
186
+ box-shadow:
187
+ 0 6px 12px rgba(0, 0, 0, 0.3),
188
+ 0 8px 16px rgba(0, 0, 0, 0.2),
189
+ inset 0 -2px 4px rgba(255, 255, 255, 0.6);
190
+ text-align: center;
191
+ position: relative;
192
+ transform: translateY(4px);
193
+ transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
194
+ cursor: pointer;
195
+ user-select: none;
196
+ }
197
+ .button:hover {
198
+ box-shadow:
199
+ 0 8px 16px rgba(0, 0, 0, 0.3),
200
+ 0 12px 24px rgba(0, 0, 0, 0.2);
201
+ transform: translateY(2px);
202
+ }
203
+ .button:active {
204
+ box-shadow:
205
+ 0 4px 8px rgba(0, 0, 0, 0.3),
206
+ 0 6px 12px rgba(0, 0, 0, 0.2);
207
+ transform: translateY(0);
208
+ }
209
+ </style>
210
+ </head>
211
+ <body>
212
+ <div class="button">
213
+ <h3 style="
214
+ font-size: 20px;
215
+ color: #ffffff;
216
+ background-image: linear-gradient(to right, #800000, #ff0000, #ffdab9);
217
+ background-clip: text;
218
+ -webkit-background-clip: text;
219
+ text-fill-color: transparent;
220
+ -webkit-text-fill-color: transparent;
221
+ margin: 0;
222
+ text-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);
223
+ ">Select the expected payout date</h3>
224
+ </div>
225
+ </body>
226
+ </html>
227
+ """
228
+
229
+ st.markdown(html_subject, unsafe_allow_html=True)
230
+
231
+
232
+ st.write("")
233
+ col1, col2 = st.columns([0.118, 0.125])
234
+ with col1:
235
+ start_date = st.date_input("Start date", value = None)
236
+ with col2:
237
+ end_date = st.date_input("End date", value = None)
238
+
239
+
240
  if credentials_file is not None:
241
+ if start_date and end_date: # Ensure dates are selected
242
+ start_date_str = start_date.strftime("%Y-%m-%d")
243
+ end_date_str = end_date.strftime("%Y-%m-%d")
 
 
 
 
 
244
 
245
+ # Read the credentials file
246
+ credentials_data = credentials_file.read().decode("utf-8")
 
 
 
 
247
 
248
+ # Check for duplicates
249
+ results = check_duplicates(credentials_data)
250
+
251
+ if "Query Result" in results:
252
+ df = results["Query Result"]
253
+
254
+ # Download buttons
255
+ csv = df.to_csv(index=False)
256
+ excel = io.BytesIO()
257
+ with pd.ExcelWriter(excel, engine='openpyxl') as writer:
258
+ df.to_excel(writer, index=False)
259
+ excel.seek(0)
260
+
261
+ col1, col2 = st.columns([0.125, 0.5])
262
+ with col1:
263
+ st.download_button(
264
+ label=":red[Download CSV]",
265
+ data=csv,
266
+ file_name="seller_sale_recon.csv",
267
+ mime="text/csv"
268
+ )
269
+
270
+ with col2:
271
+ st.download_button(
272
+ label=":red[Download Excel]",
273
+ data=excel,
274
+ file_name="seller_sale_recon.xlsx",
275
+ mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
276
+ )
277
+ else:
278
+ st.warning("Please select both the start and end dates to proceed.")