Upload 2 files
Browse files- queries.py +274 -61
queries.py
CHANGED
@@ -21,6 +21,55 @@ queries = {
|
|
21 |
invoice_generation_date is null
|
22 |
''',
|
23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
# Query 3
|
25 |
'3. Transaction components validation': '''
|
26 |
select
|
@@ -117,13 +166,14 @@ queries = {
|
|
117 |
|
118 |
# Query 10
|
119 |
'10. Positive transaction components validation': '''
|
120 |
-
SELECT
|
|
|
121 |
FROM
|
122 |
-
|
123 |
GROUP BY
|
124 |
-
|
125 |
HAVING
|
126 |
-
|
127 |
''',
|
128 |
|
129 |
|
@@ -259,87 +309,250 @@ queries = {
|
|
259 |
''',
|
260 |
|
261 |
|
262 |
-
#
|
263 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
264 |
# select
|
265 |
# A.sett_id,
|
266 |
-
#
|
267 |
-
#
|
268 |
-
#
|
269 |
-
# case when
|
|
|
|
|
270 |
# from
|
271 |
-
#
|
|
|
|
|
272 |
# sett_id,
|
273 |
-
# SUM(seller_net_collection) AS
|
274 |
-
#
|
275 |
# `fynd-db.finance_recon_tool_asia.09_seller_net_collection_daily`
|
276 |
# GROUP BY
|
277 |
-
# 1
|
278 |
-
#
|
279 |
-
#
|
|
|
|
|
280 |
# sett_id,
|
281 |
-
# SUM(total_charges)
|
282 |
-
#
|
283 |
# `fynd-db.finance_recon_tool_asia.11_seller_fees_daily`
|
284 |
# GROUP BY
|
285 |
-
# 1
|
286 |
-
#
|
287 |
-
#
|
|
|
|
|
288 |
# sett_id,
|
289 |
-
# SUM(
|
290 |
-
#
|
291 |
-
# `fynd-db.finance_recon_tool_asia.12_seller_claims_daily`
|
292 |
-
# GROUP BY
|
293 |
-
# 1
|
294 |
-
# UNION ALL
|
295 |
-
# SELECT
|
296 |
-
# sett_id,
|
297 |
-
# SUM(dispute_amount) AS NP
|
298 |
-
# FROM
|
299 |
# `fynd-db.finance_recon_tool_asia.17_seller_manual_Dispute`
|
300 |
# GROUP BY
|
301 |
-
# 1)
|
302 |
-
#
|
303 |
-
#
|
304 |
-
#
|
|
|
305 |
# sett_id,
|
306 |
-
#
|
307 |
-
# from
|
308 |
-
# `fynd-db.finance_recon_tool_asia.
|
309 |
-
#
|
310 |
-
# 1) as
|
311 |
-
# on
|
312 |
-
# A.sett_id =
|
313 |
# where
|
314 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
315 |
# ''',
|
316 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
317 |
|
318 |
-
# Query
|
319 |
-
'
|
320 |
select
|
321 |
*
|
322 |
-
from
|
323 |
-
(SELECT
|
324 |
-
*
|
325 |
-
FROM
|
326 |
-
`fynd-db.Outstanding.09_Payable_File`
|
327 |
where
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
332 |
(select
|
333 |
bag_id,
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
`fynd-db.finance_recon_tool_asia.
|
338 |
-
|
339 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
340 |
where
|
341 |
-
|
|
|
|
|
|
|
342 |
''',
|
343 |
|
|
|
|
|
|
|
|
|
|
|
|
|
344 |
# Add more queries as needed
|
345 |
}
|
|
|
21 |
invoice_generation_date is null
|
22 |
''',
|
23 |
|
24 |
+
|
25 |
+
# Query 3
|
26 |
+
# '3. Checking 01_finance all data inserted into 11_seller_fees': '''
|
27 |
+
# with commission as (select
|
28 |
+
# bag_id,
|
29 |
+
# Transaction_Type,
|
30 |
+
# Commission_in_percent
|
31 |
+
# from
|
32 |
+
# `fynd-db.finance_recon_tool_asia.11_seller_fees_logic`
|
33 |
+
# group by
|
34 |
+
# 1,2,3
|
35 |
+
# )
|
36 |
+
# select
|
37 |
+
# A.company_id,
|
38 |
+
# A.company_name,
|
39 |
+
# A.ordering_channel,
|
40 |
+
# A.sales_channel,
|
41 |
+
# A.bag_id,
|
42 |
+
# A.transaction_type,
|
43 |
+
# A.recon_status,
|
44 |
+
# A.recon_date,
|
45 |
+
# A.return_window_date,
|
46 |
+
# A.payout_window_date,
|
47 |
+
# A.inserted_date,
|
48 |
+
# B.bag_id,
|
49 |
+
# B.transaction_type,
|
50 |
+
# C.Commission_in_percent
|
51 |
+
# from `fynd-db.finance_recon_tool_asia.01_finance_avis_data_final` as A
|
52 |
+
# left join
|
53 |
+
# `fynd-db.finance_recon_tool_asia.11_seller_fees_daily` as B
|
54 |
+
# on
|
55 |
+
# A.bag_id = B.bag_id
|
56 |
+
# and A.transaction_type = B.transaction_type
|
57 |
+
# left join
|
58 |
+
# commission as C
|
59 |
+
# on
|
60 |
+
# A.bag_id = C.bag_id
|
61 |
+
# and A.transaction_type = C.transaction_type
|
62 |
+
# where
|
63 |
+
# A.transaction_type not in ('NA','SLA')
|
64 |
+
# and B.bag_id is null
|
65 |
+
# and A.recon_status not in ("return_bag_lost","bag_lost","dispute","dispute_R")
|
66 |
+
# and A.sales_channel not in ('JIOMART',"Freshpik")
|
67 |
+
# and A.company_id <> 3138
|
68 |
+
# -- and C.Commission_in_percent <> 0
|
69 |
+
# group by
|
70 |
+
# 1,2,3,4,5,6,7,8,9,10,11,12,13,14
|
71 |
+
# ''',
|
72 |
+
|
73 |
# Query 3
|
74 |
'3. Transaction components validation': '''
|
75 |
select
|
|
|
166 |
|
167 |
# Query 10
|
168 |
'10. Positive transaction components validation': '''
|
169 |
+
SELECT
|
170 |
+
CONCAT(bag_id,transaction_type,total_charges) AS Merged,
|
171 |
FROM
|
172 |
+
`fynd-db.finance_recon_tool_asia.11_seller_fees_daily`
|
173 |
GROUP BY
|
174 |
+
1
|
175 |
HAVING
|
176 |
+
COUNT(CONCAT(bag_id,transaction_type)) NOT IN (1)
|
177 |
''',
|
178 |
|
179 |
|
|
|
309 |
''',
|
310 |
|
311 |
|
312 |
+
# Query 18
|
313 |
+
'18. PPD seller amount validation': '''
|
314 |
+
select
|
315 |
+
*
|
316 |
+
from
|
317 |
+
(SELECT
|
318 |
+
*
|
319 |
+
FROM
|
320 |
+
`fynd-db.Outstanding.09_Payable_File`
|
321 |
+
where
|
322 |
+
expected_payout_date <= current_date()
|
323 |
+
and order_type = "PPD"
|
324 |
+
and lower(collection_partner) = "seller") as A
|
325 |
+
left join
|
326 |
+
(select
|
327 |
+
bag_id,
|
328 |
+
txn_id,
|
329 |
+
collected_amount
|
330 |
+
from
|
331 |
+
`fynd-db.finance_recon_tool_asia.05_partner_collection`) as B
|
332 |
+
on
|
333 |
+
A.bag_id = B.bag_id
|
334 |
+
where
|
335 |
+
B.bag_id is not null
|
336 |
+
''',
|
337 |
+
|
338 |
+
|
339 |
+
# Query 19
|
340 |
+
'19. Checking sett_id count in payout process table': '''
|
341 |
+
select
|
342 |
+
sett_id,
|
343 |
+
count(sett_id)
|
344 |
+
from `fynd-db.finance_recon_tool_asia.payout_process_table`
|
345 |
+
group by
|
346 |
+
1
|
347 |
+
having
|
348 |
+
count(sett_id) <> 1
|
349 |
+
''',
|
350 |
+
|
351 |
+
# Query 20
|
352 |
+
'20. Checking bagwise payout report': '''
|
353 |
+
select
|
354 |
+
UTR,
|
355 |
+
paid_amt,
|
356 |
+
dispute,
|
357 |
+
round(sum(Net_Payout),2) as payable,
|
358 |
+
round(sum(Net_Payout)+dispute-paid_amt) as Diff
|
359 |
+
from `fynd-db.finance_recon_tool_asia.Bag_Wise_Payout_Report`
|
360 |
+
where
|
361 |
+
UTR in (select
|
362 |
+
utr_no
|
363 |
+
from
|
364 |
+
`fynd-db.finance_recon_tool_asia.14_seller_payouts_New`
|
365 |
+
where
|
366 |
+
sett_date > "2024-04-01" )
|
367 |
+
group by
|
368 |
+
1,2,3
|
369 |
+
having Diff <> 0
|
370 |
+
''',
|
371 |
+
|
372 |
+
# Query 21
|
373 |
+
'21. Checking claimwise payout report': '''
|
374 |
+
select
|
375 |
+
SF_UTR,
|
376 |
+
total_utr_paid,
|
377 |
+
round(sum(claimable_amt),2),
|
378 |
+
round(sum(claimable_amt)-total_utr_paid) as Diff
|
379 |
+
from `fynd-db.finance_recon_tool_asia.Shipment_wise_Claim_UTR`
|
380 |
+
where
|
381 |
+
SF_UTR in ("_2414920231016000202198812",
|
382 |
+
"_2414920231016000202197711",
|
383 |
+
"_AXISCN0279665404",
|
384 |
+
"_AXISCN0312196630",
|
385 |
+
"_2414920231016000202198811")
|
386 |
+
group by
|
387 |
+
1,2
|
388 |
+
''',
|
389 |
+
|
390 |
+
# # Query 23
|
391 |
+
# '23. Checking any settlement id is updated after the payment ': '''
|
392 |
# select
|
393 |
# A.sett_id,
|
394 |
+
# sum(net_amount)as NA,
|
395 |
+
# case when NC is null then 0 else NC end as N,
|
396 |
+
# case when SF is null then 0 else SF end as S,
|
397 |
+
# case when MD is null then 0 else MD end as M,
|
398 |
+
# case when CL is null then 0 else CL end as C,
|
399 |
+
# round(sum(net_amount)-(case when NC is null then 0 else NC end)-(case when SF is null then 0 else SF end)-(case when MD is null then 0 else MD end)-(case when CL is null then 0 else CL end)) as diff
|
400 |
# from
|
401 |
+
# `fynd-db.finance_recon_tool_asia.13_seller_disbursement_payouts` as A
|
402 |
+
# left join
|
403 |
+
# (select
|
404 |
# sett_id,
|
405 |
+
# SUM(seller_net_collection) AS NC
|
406 |
+
# from
|
407 |
# `fynd-db.finance_recon_tool_asia.09_seller_net_collection_daily`
|
408 |
# GROUP BY
|
409 |
+
# 1) as B
|
410 |
+
# on
|
411 |
+
# A.sett_id = B.sett_id
|
412 |
+
# left join
|
413 |
+
# (Select
|
414 |
# sett_id,
|
415 |
+
# SUM(total_charges) as SF
|
416 |
+
# from
|
417 |
# `fynd-db.finance_recon_tool_asia.11_seller_fees_daily`
|
418 |
# GROUP BY
|
419 |
+
# 1) as C
|
420 |
+
# on
|
421 |
+
# A.sett_id = C.sett_id
|
422 |
+
# left join
|
423 |
+
# (Select
|
424 |
# sett_id,
|
425 |
+
# SUM(dispute_amount) as MD
|
426 |
+
# from
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
427 |
# `fynd-db.finance_recon_tool_asia.17_seller_manual_Dispute`
|
428 |
# GROUP BY
|
429 |
+
# 1) as D
|
430 |
+
# on
|
431 |
+
# A.sett_id = D.sett_id
|
432 |
+
# left join
|
433 |
+
# (Select
|
434 |
# sett_id,
|
435 |
+
# SUM(claimable_amt) as CL
|
436 |
+
# from
|
437 |
+
# `fynd-db.finance_recon_tool_asia.12_seller_claims_daily`
|
438 |
+
# GROUP BY
|
439 |
+
# 1) as E
|
440 |
+
# on
|
441 |
+
# A.sett_id = E.sett_id
|
442 |
# where
|
443 |
+
# payout_id in ("2250_OE_COD_19_SD_034_FY24",
|
444 |
+
# "2250_OE_COD_21_SD_034_FY24",
|
445 |
+
# "0292_FS_COD_AC_SD_034_FY24",
|
446 |
+
# "0517_OE_COD_AC_SD_034_FY24",
|
447 |
+
# "0042_OE_COD_05_SD_034_FY24",
|
448 |
+
# "0034_OM_COD_AC_SD_034_FY24",
|
449 |
+
# "0021_OE_COD_AC_SD_034_FY24",
|
450 |
+
# "0046_OE_COD_10_SD_034_FY24",
|
451 |
+
# "0442_OE_COD_07_SD_034_FY24",
|
452 |
+
# "0320_OE_COD_28_SD_034_FY24",
|
453 |
+
# "0046_OE_COD_13_SD_034_FY24",
|
454 |
+
# "0269_OE_COD_04_SD_034_FY24",
|
455 |
+
# "3557_OE_COD_AC_SD_034_FY24",
|
456 |
+
# "0025_FS_COD_AC_SD_034_FY24",
|
457 |
+
# "3523_FS_COD_AC_SD_034_FY24",
|
458 |
+
# "0320_OM_COD_AC_SD_034_FY24",
|
459 |
+
# "2467_OE_COD_AC_SD_034_FY24",
|
460 |
+
# "0680_UN_COD_MA_SD_034_FY24",
|
461 |
+
# "0021_FS_COD_AC_SD_034_FY24",
|
462 |
+
# "0442_FS_COD_AC_SD_034_FY24",
|
463 |
+
# "0046_FS_COD_AC_SD_034_FY24",
|
464 |
+
# "0046_OE_COD_14_SD_034_FY24",
|
465 |
+
# "0046_OE_COD_09_SD_034_FY24",
|
466 |
+
# "1076_OE_COD_17_SD_034_FY24",
|
467 |
+
# "0334_FS_COD_AC_SD_034_FY24",
|
468 |
+
# "0046_OE_COD_08_SD_034_FY24",
|
469 |
+
# "0334_OE_COD_06_SD_034_FY24",
|
470 |
+
# "2250_OE_COD_22_SD_034_FY24",
|
471 |
+
# "0002_FS_COD_AC_SD_034_FY24",
|
472 |
+
# "2411_OM_COD_AC_SD_034_FY24")
|
473 |
+
# group by
|
474 |
+
# 1,3,4,5,NC,SF,MD,CL
|
475 |
+
# having
|
476 |
+
# round(sum(net_amount)-(case when NC is null then 0 else NC end)-(case when SF is null then 0 else SF end)-(case when MD is null then 0 else MD end)) <> 0
|
477 |
# ''',
|
478 |
|
479 |
+
# Query 22
|
480 |
+
'22. Checking any old data inserted into new table': '''
|
481 |
+
select
|
482 |
+
A.bag_id,
|
483 |
+
collection_partner,
|
484 |
+
Settlement_type,
|
485 |
+
inserted_date,
|
486 |
+
B.bag_id,
|
487 |
+
B.Transaction_type
|
488 |
+
from `fynd-db.finance_recon_tool_asia.01_finance_avis_data_final` as A
|
489 |
+
left join
|
490 |
+
`fynd-db.finance_dwh.Brand_Settlement_pulse` as B
|
491 |
+
on A.bag_id = B.bag_id
|
492 |
+
and (case when Settlement_type = 'collection' then 'Sale'when Settlement_type = 'refund' then 'Return' else 'Claim' end) = B.Transaction_type
|
493 |
+
where
|
494 |
+
Settlement_type <> 'NA'
|
495 |
+
and B.bag_id is not null
|
496 |
+
group by
|
497 |
+
1,2,3,4,5,6
|
498 |
+
''',
|
499 |
|
500 |
+
# Query 23
|
501 |
+
'23. Checking old lost claim check inserted into new table': '''
|
502 |
select
|
503 |
*
|
504 |
+
from `fynd-db.finance_recon_tool_asia.01_finance_avis_data_final`
|
|
|
|
|
|
|
|
|
505 |
where
|
506 |
+
Bag_ID in (select
|
507 |
+
Bag_ID
|
508 |
+
from `fynd-db.finance_dwh.Brand_Lost_settlement`
|
509 |
+
group by
|
510 |
+
1)
|
511 |
+
and transaction_type = 'Claim'
|
512 |
+
''',
|
513 |
+
|
514 |
+
|
515 |
+
# Query 24
|
516 |
+
'24. Checking duplicate count in bag_wise payout report ': '''
|
517 |
+
with bag_count as
|
518 |
(select
|
519 |
bag_id,
|
520 |
+
transaction_type,
|
521 |
+
concat(bag_id,transaction_type) as merged,
|
522 |
+
count(concat(bag_id,transaction_type)) as bag_count
|
523 |
+
from `fynd-db.finance_recon_tool_asia.Bag_Wise_Payout_Report`
|
524 |
+
group by
|
525 |
+
1,2,3)
|
526 |
+
|
527 |
+
select
|
528 |
+
A.bag_id,
|
529 |
+
company_id,
|
530 |
+
company_name,
|
531 |
+
Payment_Date,
|
532 |
+
A.transaction_type,
|
533 |
+
UTR,
|
534 |
+
concat(A.bag_id,A.transaction_type) as merged,
|
535 |
+
bag_count,
|
536 |
+
seller_net_collection,
|
537 |
+
total_charges,
|
538 |
+
Net_Payout
|
539 |
+
from `fynd-db.finance_recon_tool_asia.Bag_Wise_Payout_Report` as A
|
540 |
+
left join
|
541 |
+
bag_count as B
|
542 |
+
on
|
543 |
+
concat(A.bag_id,A.transaction_type) = B.merged
|
544 |
where
|
545 |
+
bag_count <> 1
|
546 |
+
group by
|
547 |
+
1,2,3,4,5,6,7,8,9,10,11
|
548 |
+
|
549 |
''',
|
550 |
|
551 |
+
|
552 |
+
# Seller sale validation query
|
553 |
+
|
554 |
+
|
555 |
+
|
556 |
+
|
557 |
# Add more queries as needed
|
558 |
}
|