File size: 11,508 Bytes
6f4113b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344

queries = {
    # Query 1
    '1. fynd-db.finance_recon_tool_asia.01_finance_avis_data_final': '''
        select
        bag_id,
        concat(bag_id,Recon_Status,Settlement_type,Transaction_Type) as Merged,
        count(concat(bag_id,Recon_Status,Settlement_type,Transaction_Type))
        from `fynd-db.finance_recon_tool_asia.01_finance_avis_data_final`
        group by
        1,2
        having count(concat(bag_id,Recon_Status,Settlement_type,Transaction_Type)) not in (1)
    ''',

    # Query 2
    '2. Seller fees date validation': '''
        select
        *
        from `fynd-db.finance_recon_tool_asia.11_seller_fees_daily`
        where
        invoice_generation_date is null
    ''',

    # Query 3
    '3. Transaction components validation': '''
        select
        bag_id,
        transaction_type,
        inserted_date,
        round(transaction_fee+packaging_fee+logistics_charges+refund_support_fees+sla_charges-net_charges,0) as diff
        from `fynd-db.finance_recon_tool_asia.11_seller_fees_daily`
        where
        round(transaction_fee+packaging_fee+logistics_charges+refund_support_fees+sla_charges-net_charges,0) not in (0,-1,-1)
        and inserted_date > '2023-09-30'
        group by 1,2,3, transaction_fee,packaging_fee,refund_support_fees,sla_charges,net_charges,logistics_charges
    ''',

    # Query 4
    '4. Transactions in net collection validation': '''
        select
        concat(bag_id,Settlement_type) as Merged,
        count(concat(bag_id,Settlement_type))
        from `fynd-db.finance_recon_tool_asia.09_seller_net_collection_daily`
        group by 1
        having  
        count(concat(bag_id,Settlement_type)) not in (1)
    ''',

    # Query 5
    '5. Transactions in seller fees validation': '''
        select
        bag_id,
        concat(bag_id,transaction_type) as Merged,
        count(concat(bag_id,transaction_type))
        from `fynd-db.finance_recon_tool_asia.11_seller_fees_daily`
        group by 1,2
        having  
        count(concat(bag_id,transaction_type)) not in (1)
    ''',


    # Query 6
    '6. Transactions in seller claims validation': '''
        select
        current_shipment_id,
        concat(current_shipment_id,transaction_type) as Merged,
        count(concat(current_shipment_id,transaction_type))
        from `fynd-db.finance_recon_tool_asia.12_seller_claims_daily`
        group by 1,2
        having  
        count(concat(current_shipment_id,transaction_type)) not in (1)
    ''',


    # Query 7
    '7. Aggregate liability validation': '''
        select
        *
        from `fynd-db.finance_recon_tool_asia.12_seller_claims_daily`
        where
        aggregate_liability is null
    ''',


    # Query 8
    '8. Lost claim validation': '''
        select
        *
        from `fynd-db.finance_recon_tool_asia.01_finance_avis_data_final` as A
        left join
        `fynd-db.finance_recon_tool_asia.12_seller_claims_daily` as B
        on
        A.current_shipment_id = B.current_shipment_id
        where
        A.claim_settle_date is not null
        and A.transaction_type = 'Claim'
        and A.dp_partner = 'fynd'
        and B.current_shipment_id is null
    ''',
    


    # Query 9
    '9. Gstin validation': '''
        select
        company_id,
        company_name,
        ordering_channel
        from `fynd-db.finance_recon_tool_asia.11_seller_fees_daily`
        where
        company_gstn is null
        group by
        1,2,3
    ''',



    # Query 10
    '10. Positive transaction components validation': '''
        select
        *
        from `fynd-db.finance_recon_tool_asia.11_seller_fees_daily`
        where
        transaction_type in ('Sale','SLA','Claim')
        and net_charges > 0
    ''',


     # Query 11
    '11. Negative transaction components validation': '''
        select
        *
        from `fynd-db.finance_recon_tool_asia.11_seller_fees_daily`
        where
        transaction_type = 'Return'
        and net_charges < 0
    ''',


    # Query 12
    '12. GST Tag validation': '''
        select
        company_id,
        company_name,
        ordering_channel,
        company_gstn,
        gst_tag,
        case WHEN LENGTH(company_gstn) = 10 then "SGST"
        when SUBSTRING(company_gstn,1,2) = '27' then "SGST" else "IGST" end as Tag,
        case when gst_tag = (case WHEN LENGTH(company_gstn) = 10 then "SGST"
        when SUBSTRING(company_gstn,1,2) = '27' then "SGST" else "IGST" end) then "Match" else "Not_Match" end as CC
        from `fynd-db.finance_recon_tool_asia.11_seller_fees_daily`
        where
        (case when gst_tag = (case WHEN LENGTH(company_gstn) = 10 then "SGST"
        when SUBSTRING(company_gstn,1,2) = '27' then "SGST" else "IGST" end) then "Match" else "Not_Match" end) = "Not_Match"
        group by 1,2,3,4,5,6
    ''',

     # Query 13
    '13. 09_Net collection all data validation': '''
        select
        A.company_id,
        A.company_name,
        A.ordering_channel,
        A.bag_id,
        A.Settlement_type,
        A.recon_status,
        A.recon_date,
        A.inserted_date,
        B.bag_id,
        B.Settlement_type
        from `fynd-db.finance_recon_tool_asia.01_finance_avis_data_final` as A
        left join
        `fynd-db.finance_recon_tool_asia.09_seller_net_collection_daily` as B
        on
        A.bag_id = B.bag_id
        and A.Settlement_type = B.Settlement_type
        where
        A.Settlement_type not in ('NA','SLA')
        and A.recon_status in ('delivery_done','return_bag_delivered','return_bag_picked')
        and B.bag_id is null 
        and (case when A.Settlement_type = 'collection' and A.collection_partner = 'fynd' then 'yes' 
        when A.Settlement_type = 'refund' and A.refund_partner = 'fynd' then 'yes' else 'no' end) = 'yes'
        group by
        1,2,3,4,5,6,7,8,9,10
    ''',


     # Query 14
    '14. Net collection collection & refund validation': '''
        select
        bag_id,
        settlement_type,
        collection_partner,
        refund_partner,
        case when settlement_type in ('collection','Claim',"dispute","rectify","rectify_R") and collection_partner = 'fynd' then 'Yes' when settlement_type = 'refund' and refund_partner = 'fynd' then 'Yes' else 'No' end as Comment
        from `fynd-db.finance_recon_tool_asia.09_seller_net_collection_daily`
        where
        (case when settlement_type in ('collection','Claim',"dispute","rectify","rectify_R") and collection_partner = 'fynd' then 'Yes' when settlement_type = 'refund' and refund_partner = 'fynd' then 'Yes' else 'No' end) = 'No'
    ''',


    # Query 15
    '15. 09_Net collection collection & refund validation': '''
        select
        A.bag_id,
        B.bag_id,
        A.settlement_type,
        B.settlement_type,
        A.transaction_type,
        A.collection_partner,
        A.refund_partner,
        case when A.settlement_type = 'collection' and A.collection_partner = 'fynd' then 'Yes' when A.settlement_type = 'refund' and A.refund_partner = 'fynd' then 'Yes' else 'No' end as Comment
        from `fynd-db.finance_recon_tool_asia.01_finance_avis_data_final` as A
        left join
        `fynd-db.finance_recon_tool_asia.09_seller_net_collection_daily` as B
        on
        A.bag_id = B.bag_id 
        and A.settlement_type = B.settlement_type
        where
        A.settlement_type <> 'NA'
        and A.recon_status not in ("bag_lost","return_bag_lost")
        and (case when A.settlement_type = 'collection' and A.collection_partner = 'fynd' then 'yes' when A.settlement_type = 'refund' and A.refund_partner = 'fynd' then 'yes' else 'No' end) = 'yes'  
        and (case when A.transaction_type = 'Sale' and A.collection_partner = 'fynd' then 'Yes' when A.transaction_type = 'Return' and A.refund_partner = 'fynd' then 'Yes' when A.transaction_type = 'Claim' and A.collection_partner = 'fynd' then 'Yes' else 'No' end) = 'Yes'
        and B.bag_id is null
    ''',


    # Query 16
    '16. NA settlement validation': '''
        select
        *
        from `fynd-db.finance_recon_tool_asia.09_seller_net_collection_daily`
        where
        -- settlement_type = 'NA'
        (case when settlement_type in ('collection','Claim','rectify','rectify_R') and collection_partner = 'fynd' then 'Yes' when settlement_type = 'refund' and refund_partner = 'fynd' then 'Yes' else 'No'end ) = 'No'
    ''',


    # Query 17
    '17. Fynd collection placed bags validation': '''
        select
        A.bag_id,
        B.bag_id,
        A.order_type,
        A.transaction_type,
        case when B.settlement_type = 'collection' then 'Sale' else 'Return' end as transaction_type,
        from `fynd-db.finance_recon_tool_asia.11_seller_fees_daily` as A
        left join
        `fynd-db.finance_recon_tool_asia.09_seller_net_collection_daily` as B
        on
        A.bag_id = B.bag_id
        and A.transaction_type = (case when B.settlement_type = 'collection' then 'Sale' when B.settlement_type = 'refund' then 'Return' else 'NA' end )
        where
        transaction_type <> 'SLA'
        and (case when A.transaction_type = 'Sale' and A.collection_partner = 'fynd' then 'yes' when A.transaction_type = 'Return' and A.refund_partner = 'fynd' then 'yes' else 'no'end) = 'yes'
        and B.bag_id is null
    ''',


    #  # Query 18
    # '18. Disbursement table validation': '''
    #     select
    #     A.sett_id,
    #     B.sett_id,
    #     NP,
    #     net_amount,
    #     case when A.sett_id = B.sett_id and round(NP - net_amount,0) in (0,1) then 'Match' else "Not_Match" end as Diff
    #     from
    #     (SELECT
    #     sett_id,
    #     SUM(seller_net_collection) AS NP
    #     FROM
    #     `fynd-db.finance_recon_tool_asia.09_seller_net_collection_daily`
    #     GROUP BY
    #     1
    #     UNION ALL
    #     SELECT
    #     sett_id,
    #     SUM(total_charges) AS NP
    #     FROM
    #     `fynd-db.finance_recon_tool_asia.11_seller_fees_daily`
    #     GROUP BY
    #     1
    #     UNION ALL
    #     SELECT
    #     sett_id,
    #     SUM(claimable_amt) AS NP
    #     FROM
    #     `fynd-db.finance_recon_tool_asia.12_seller_claims_daily`
    #     GROUP BY
    #     1
    #     UNION ALL
    #     SELECT
    #     sett_id,
    #     SUM(dispute_amount) AS NP
    #     FROM
    #     `fynd-db.finance_recon_tool_asia.17_seller_manual_Dispute`
    #     GROUP BY
    #     1)  as A
    #     --left join
    #     right join
    #     (select
    #     sett_id,
    #     sum(net_amount) as net_amount
    #     from  
    #     `fynd-db.finance_recon_tool_asia.disbursement_summary`
    #     group by
    #     1) as B
    #     on
    #     A.sett_id = B.sett_id
    #     where
    #     (case when A.sett_id = B.sett_id and round(NP - net_amount,0) in (0,1) then 'Match' else "Not_Match" end) = 'Not_Match'
    # ''',


    # Query 19
    '18. PPD validation': '''
        select
        *
        from
        (SELECT
        *
        FROM
        `fynd-db.Outstanding.09_Payable_File`
        where
        expected_payout_date <= current_date()
        and order_type = "PPD"
        and lower(collection_partner) = "seller") as A
        left join
        (select
        bag_id,
        txn_id,
        collected_amount
        from
        `fynd-db.finance_recon_tool_asia.05_partner_collection`) as B
        on 
        A.bag_id = B.bag_id
        where
        B.bag_id is not null
    ''',

    # Add more queries as needed
}