-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathCE Bank Statement Import Execution.sql
More file actions
526 lines (525 loc) · 19.5 KB
/
CE Bank Statement Import Execution.sql
File metadata and controls
526 lines (525 loc) · 19.5 KB
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
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
/*************************************************************************/
/* */
/* (c) 2010-2024 Enginatics GmbH */
/* www.enginatics.com */
/* */
/*************************************************************************/
-- Report Name: CE Bank Statement Import Execution
-- Description: Application: Cash Management
Source: Bank Statement Import Execution Report
Short Name: CEIMPERR
DB package: CE_CEXINERR_XMLP_PKG
-- Excel Examle Output: https://www.enginatics.com/example/ce-bank-statement-import-execution/
-- Library Link: https://www.enginatics.com/reports/ce-bank-statement-import-execution/
-- Run Report: https://demo.enginatics.com/
select
/* Q1. successfuly imported statements with no errors */
cbbv.bank_name bank_name,
cbbv.bank_branch_name bank_branch_name,
cbagv.bank_account_name bank_account_name,
cbagv.bank_account_num bank_account_number,
cbagv.currency_code account_currency,
'Processed' import_status,
null error_type,
csh.statement_number statement_number,
csh.statement_date statement_date,
(select
cshi.creation_date
from
ce_statement_headers_int cshi
where
cshi.statement_number = csh.statement_number
and cshi.currency_code = nvl(csh.currency_code,cbagv.currency_code)
and cshi.bank_account_num = cbagv.bank_account_num
and nvl(cshi.org_id,-99) = nvl(csh.org_id,-99)
) statement_interface_date,
csh.doc_sequence_value doc_sequence_value,
csl.line_number line_number,
csl.trx_date trx_date,
xxen_util.meaning(csl.status,'STATEMENT_LINE_STATUS',260) line_status,
null message_name,
nvl(csl.amount,0) amount,
nvl(csl.currency_code,
cbagv.currency_code
) trx_currency,
cl2.meaning trx_type,
csl.bank_trx_number trx_no,
'CE' application
from
ce_lookups cl2,
ce_bank_accts_gt_v cbagv,
ce_bank_branches_v cbbv,
ce_statement_headers csh,
ce_statement_lines csl
where
1=1
and nvl(:p_show_errors_only,'No') != 'Yes'
and cbbv.branch_party_id = cbagv.bank_branch_id
and cbagv.bank_account_id = csh.bank_account_id
and csl.statement_header_id = csh.statement_header_id
and cl2.lookup_type (+) = 'BANK_TRX_TYPE'
and cl2.lookup_code (+) = csl.trx_type
and not exists
(select
null
from
ar_cash_receipts_all acra,
ar_cash_receipt_history_all acrha,
ce_statement_reconcils_all csra
where
csra.statement_line_id = csl.statement_line_id
and csra.reference_type in ('RECEIPT','DM REVERSAL')
and csra.current_record_flag = 'Y'
and csra.status_flag = 'M'
and acrha.cash_receipt_history_id = csra.reference_id
and acra.cash_receipt_id = acrha.cash_receipt_id
and acra.comments = 'Created by Auto Bank Rec'
)
and not exists
(select
null
from
ce_reconciliation_errors clie
where
csl.statement_line_id = clie.statement_line_id
and clie.statement_line_id is not null
and csl.status != 'EXTERNAL'
)
--
union all
--
select
/* Q2. miscellaneous receipts created */
cbbv.bank_name bank_name,
cbbv.bank_branch_name bank_branch_name,
cbagv.bank_account_name bank_account_name,
cbagv.bank_account_num bank_account_number,
cbagv.currency_code account_currency,
'Processed' import_status,
cl1.meaning error_type,
csh.statement_number statement_number,
csh.statement_date statement_date,
(select
cshi.creation_date
from
ce_statement_headers_int cshi
where
cshi.statement_number = csh.statement_number
and cshi.currency_code = nvl(csh.currency_code,cbagv.currency_code)
and cshi.bank_account_num = cbagv.bank_account_num
and nvl(cshi.org_id,-99) = nvl(csh.org_id,-99)
) statement_interface_date,
csh.doc_sequence_value doc_sequence_value,
csl.line_number line_number,
csl.trx_date trx_date,
xxen_util.meaning(csl.status,'STATEMENT_LINE_STATUS',260) line_status,
null message_name,
nvl(csl.amount,0) amount,
acra.currency_code trx_currency,
cl2.meaning trx_type,
acra.receipt_number trx_no,
'CE' application
from
ce_lookups cl1,
ce_lookups cl2,
ce_bank_accts_gt_v cbagv,
ce_bank_branches_v cbbv,
ce_statement_headers csh,
ce_statement_lines csl,
ar_cash_receipts_all acra,
ar_cash_receipt_history_all acrha,
ce_statement_reconcils_all csra
where
1=1
and cbbv.branch_party_id = cbagv.bank_branch_id
and cbagv.bank_account_id = csh.bank_account_id
and csh.statement_header_id = csl.statement_header_id
and csra.statement_line_id = csl.statement_line_id
and csra.reference_type in ('RECEIPT','DM REVERSAL')
and csra.current_record_flag = 'Y'
and csra.status_flag = 'M'
and acrha.cash_receipt_history_id = csra.reference_id
and acra.cash_receipt_id = acrha.cash_receipt_id
and acra.comments = 'Created by Auto Bank Rec'
and cl1.lookup_type = 'ABR_REPORT_EXCEPTIONS'
and cl1.lookup_code = 'MISC_RECEIPT_CREATED'
and cl2.lookup_type (+) = 'BANK_TRX_TYPE'
and cl2.lookup_code (+) = csl.trx_type
--
union all
--
select /*+ push_pred(clie) */
/*Q3. reconciliation errors - line level */
cbbv.bank_name bank_name,
cbbv.bank_branch_name bank_branch_name,
cbagv.bank_account_name bank_account_name,
cbagv.bank_account_num bank_account_number,
cbagv.currency_code account_currency,
'Processed' import_status,
cl1.description error_type,
csh.statement_number statement_no,
csh.statement_date statement_date,
(select
cshi.creation_date
from
ce_statement_headers_int cshi
where
cshi.statement_number = csh.statement_number
and cshi.currency_code = nvl(csh.currency_code,cbagv.currency_code)
and cshi.bank_account_num = cbagv.bank_account_num
and nvl(cshi.org_id,-99) = nvl(csh.org_id,-99)
) statement_interface_date,
csh.doc_sequence_value doc_sequence_value,
csl.line_number line_no,
csl.trx_date trx_date,
xxen_util.meaning(csl.status,'STATEMENT_LINE_STATUS',260) line_status,
clie.message_name,
nvl(csl.amount,0) amount,
nvl(csl.currency_code,cbagv.currency_code) c_currency_code,
cl2.meaning trx_type,
csl.bank_trx_number trx_no,
nvl(clie.application_short_name,'CE') application_short_name
from
ce_lookups cl1,
ce_lookups cl2,
ce_bank_accts_gt_v cbagv,
ce_bank_branches_v cbbv,
ce_statement_headers csh,
ce_statement_lines csl,
(select distinct
cre.statement_header_id,
cre.statement_line_id,
cre.application_short_name,
listagg (ce_cexinerr_xmlp_pkg.c_prt_message_nameformula(cre.message_name),', ') within group (order by cre.message_name) message_name
from
ce_reconciliation_errors cre
group by
cre.statement_header_id,
cre.statement_line_id,
cre.application_short_name
) clie
where
1=1
and cbbv.branch_party_id = cbagv.bank_branch_id
and cbagv.bank_account_id = csh.bank_account_id
and csh.statement_header_id = csl.statement_header_id
and csh.statement_header_id = clie.statement_header_id
and csl.statement_line_id = clie.statement_line_id
and clie.statement_line_id is not null
and csl.status != 'EXTERNAL'
and cl1.lookup_type = 'ABR_REPORT_EXCEPTIONS'
and cl1.lookup_code = 'RECONCILIATION'
and cl2.lookup_type (+) = 'BANK_TRX_TYPE'
and cl2.lookup_code (+) = csl.trx_type
--
union all
--
select /*+ push_pred(clie) */
/* Q4. reconciliation errors - header level */
cbbv.bank_name bank_name,
cbbv.bank_branch_name bank_branch_name,
cbagv.bank_account_name bank_account_name,
cbagv.bank_account_num bank_account_number,
cbagv.currency_code account_currency,
'Processed' import_status,
cl1.description error_type,
csh.statement_number statement_no,
csh.statement_date statement_date,
(select
cshi.creation_date
from
ce_statement_headers_int cshi
where
cshi.statement_number = csh.statement_number
and cshi.currency_code = nvl(csh.currency_code,cbagv.currency_code)
and cshi.bank_account_num = cbagv.bank_account_num
and nvl(cshi.org_id,-99) = nvl(csh.org_id,-99)
) statement_interface_date,
csh.doc_sequence_value doc_sequence_value,
0 line_no,
to_date(null) trx_date,
null line_status,
clie.message_name,
to_number(null) amount,
cbagv.currency_code c_currency_code,
null trx_type,
null trx_no,
nvl(clie.application_short_name,'CE') application_short_name
from
ce_lookups cl1,
ce_bank_accts_gt_v cbagv,
ce_bank_branches_v cbbv,
ce_statement_headers csh,
(select distinct
cre.statement_header_id,
cre.statement_line_id,
cre.application_short_name,
listagg (ce_cexinerr_xmlp_pkg.c_prt_message_nameformula(cre.message_name),', ') within group (order by cre.message_name) message_name
from
ce_reconciliation_errors cre
group by
cre.statement_header_id,
cre.statement_line_id,
cre.application_short_name
) clie
where
1=1
and cbbv.branch_party_id = cbagv.bank_branch_id
and cbagv.bank_account_id = csh.bank_account_id
and clie.statement_line_id is null
and csh.statement_header_id = clie.statement_header_id
and cl1.lookup_type = 'ABR_REPORT_EXCEPTIONS'
and cl1.lookup_code = 'RECONCILIATION'
--
union all
--
(
select /*+ push_pred(clie) */
/*Q5. header interface errors */
cbbv.bank_name bank_name,
cbbv.bank_branch_name bank_branch_name,
cbagv.bank_account_name bank_account_name,
cbagv.bank_account_num bank_account_number,
cbagv.currency_code account_currency,
'Error' import_status,
cl1.description error_type,
clie.statement_number statement_no,
trunc(csh.statement_date) statement_date,
csh.creation_date statement_interface_date,
to_number(null) doc_sequence_value,
0 line_no,
csh.statement_date trx_date,
null line_status,
clie.message_name,
0 amount,
' ' c_currency_code,
' ' trx_type,
' ' trx_no,
nvl(clie.application_short_name,'CE') application_short_name
from
ce_lookups cl1,
ce_statement_headers_int csh,
ce_bank_accts_gt_v cbagv,
ce_bank_branches_v cbbv,
(select distinct
chie.bank_account_num,
chie.statement_number,
chie.currency_code,
chie.application_short_name,
listagg (ce_cexinerr_xmlp_pkg.c_prt_message_nameformula(chie.message_name),', ') within group (order by chie.message_name) message_name
from
ce_header_interface_errors chie
group by
chie.bank_account_num,
chie.statement_number,
chie.currency_code,
chie.application_short_name
) clie
where
1=1
and cbbv.branch_party_id = cbagv.bank_branch_id
and clie.bank_account_num = cbagv.bank_account_num
and cbagv.currency_code = csh.currency_code
and csh.bank_account_num = clie.bank_account_num
and csh.statement_number = clie.statement_number
and csh.currency_code = clie.currency_code
and cl1.lookup_type = 'ABR_REPORT_EXCEPTIONS'
and cl1.lookup_code = 'STATEMENT'
and nvl(csh.record_status_flag,'N') != 'T' -- not transferred
--
union
--
select /*+ push_pred(clie) */
/*Q6. header interface errors, in case the stmt has been transfered to ce_statement_headers and there're warnings during transfer */
cbbv.bank_name bank_name,
cbbv.bank_branch_name bank_branch_name,
cbagv.bank_account_name bank_account_name,
cbagv.bank_account_num bank_account_number,
cbagv.currency_code account_currency,
'Processed' import_status,
cl1.description error_type,
clie.statement_number statement_no,
csh.statement_date statement_date,
(select
cshi.creation_date
from
ce_statement_headers_int cshi
where
cshi.statement_number = csh.statement_number
and cshi.currency_code = nvl(csh.currency_code,cbagv.currency_code)
and cshi.bank_account_num = cbagv.bank_account_num
and nvl(cshi.org_id,-99) = nvl(csh.org_id,-99)
) statement_interface_date,
to_number(null) doc_sequence_value,
0 line_no,
csh.statement_date trx_date,
null line_status,
clie.message_name,
0 amount,
' ' c_currency_code,
' ' trx_type,
' ' trx_no,
nvl(clie.application_short_name,'CE') application_short_name
from
ce_lookups cl1,
ce_statement_headers csh,
ce_bank_accts_gt_v cbagv,
ce_bank_branches_v cbbv,
(select distinct
chie.bank_account_num,
chie.statement_number,
chie.currency_code,
chie.application_short_name,
listagg (ce_cexinerr_xmlp_pkg.c_prt_message_nameformula(chie.message_name),', ') within group (order by chie.message_name) message_name
from
ce_header_interface_errors chie
group by
chie.bank_account_num,
chie.statement_number,
chie.currency_code,
chie.application_short_name
) clie
where
1=1
and cbbv.branch_party_id = cbagv.bank_branch_id
and csh.bank_account_id = cbagv.bank_account_id
and clie.bank_account_num = cbagv.bank_account_num
and clie.statement_number = csh.statement_number
and clie.currency_code = nvl(csh.currency_code,cbagv.currency_code)
and cl1.lookup_type = 'ABR_REPORT_EXCEPTIONS'
and cl1.lookup_code = 'STATEMENT'
)
--
union all
--
select /*+ push_pred(clie) */
/*Q7. line interface errors */
cbbv.bank_name bank_name,
cbbv.bank_branch_name bank_branch_name,
cbagv.bank_account_name bank_account_name,
cbagv.bank_account_num bank_account_number,
cbagv.currency_code account_currency,
'Error' import_status,
cl1.description error_type,
clie.statement_number statement_no,
trunc(csh.statement_date) statement_date,
csh.creation_date statement_interface_date,
to_number(null) doc_sequence_value,
clie.line_number line_no,
csl.trx_date trx_date,
'Error' line_status,
clie.message_name,
nvl(csl.amount,0) amount,
nvl(curr.currency_code, cbagv.currency_code) c_currency_code,
' ' trx_type,
' ' trx_no,
nvl(clie.application_short_name,'CE') application_short_name
from
fnd_currencies curr,
ce_lookups cl1,
ce_statement_headers_int csh,
ce_statement_lines_interface csl,
ce_bank_accts_gt_v cbagv,
ce_bank_branches_v cbbv,
(select distinct
clie.bank_account_num,
clie.statement_number,
clie.line_number,
clie.bank_acct_currency_code,
clie.application_short_name,
listagg (ce_cexinerr_xmlp_pkg.c_prt_message_nameformula(clie.message_name),', ') within group (order by clie.message_name) message_name
from
ce_line_interface_errors clie
group by
clie.bank_account_num,
clie.statement_number,
clie.line_number,
clie.bank_acct_currency_code,
clie.application_short_name
) clie
where
1=1
and cbbv.branch_party_id = cbagv.bank_branch_id
and cbagv.bank_account_num = csh.bank_account_num
and cbagv.currency_code = csh.currency_code
and csh.bank_account_num = csl.bank_account_num
and csh.statement_number = csl.statement_number
and csh.currency_code = csl.bank_acct_currency_code
and clie.bank_account_num = cbagv.bank_account_num
and csl.line_number = clie.line_number
and csl.statement_number = clie.statement_number
and csl.bank_account_num = clie.bank_account_num
and csl.bank_acct_currency_code = clie.bank_acct_currency_code
and curr.currency_code(+) = csl.currency_code
and cl1.lookup_type = 'ABR_REPORT_EXCEPTIONS'
and cl1.lookup_code = 'LINE'
union all
select
/* Q8. statement headers with no lines */
cbbv.bank_name bank_name,
cbbv.bank_branch_name bank_branch_name,
cbagv.bank_account_name bank_account_name,
cbagv.bank_account_num bank_account_number,
cbagv.currency_code account_currency,
'Processed' import_status,
'No Statement Lines' error_type,
csh.statement_number statement_number,
csh.statement_date statement_date,
(select
cshi.creation_date
from
ce_statement_headers_int cshi
where
cshi.statement_number = csh.statement_number
and cshi.currency_code = nvl(csh.currency_code,cbagv.currency_code)
and cshi.bank_account_num = cbagv.bank_account_num
and nvl(cshi.org_id,-99) = nvl(csh.org_id,-99)
) statement_interface_date,
csh.doc_sequence_value doc_sequence_value,
to_number(null) line_number,
to_date(null) trx_date,
null line_status,
'No Statement Lines' message_name,
to_number(null) amount,
null trx_currency,
null trx_type,
null trx_no,
'CE' application
from
ce_bank_accts_gt_v cbagv,
ce_bank_branches_v cbbv,
ce_statement_headers csh
where
1=1
and cbbv.branch_party_id = cbagv.bank_branch_id
and cbagv.bank_account_id = csh.bank_account_id
and not exists -- no statement lines
(select
null
from
ce_statement_lines csl
where
csl.statement_header_id = csh.statement_header_id
)
and not exists -- will be picked up in Q4 header recon error
(select
null
from
ce_reconciliation_errors cre
where
cre.statement_line_id is null
and cre.statement_header_id = csh.statement_header_id
)
and not exists -- will be picked up in Q6 header interface errors
(select
null
from
ce_header_interface_errors chie
where
chie.bank_account_num = cbagv.bank_account_num
and chie.statement_number = csh.statement_number
and chie.currency_code = nvl(csh.currency_code,cbagv.currency_code)
)
--
order by
1,2,3,4,9,12