-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathAP Invoice on Hold 11i.sql
More file actions
388 lines (387 loc) · 15.7 KB
/
AP Invoice on Hold 11i.sql
File metadata and controls
388 lines (387 loc) · 15.7 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
/*************************************************************************/
/* */
/* (c) 2010-2024 Enginatics GmbH */
/* www.enginatics.com */
/* */
/*************************************************************************/
-- Report Name: AP Invoice on Hold 11i
-- Description: Based on Oracle standard Invoice on Hold report
Source: Invoice on Hold Report (XML)
Short Name: APXINROH_XML
-- Excel Examle Output: https://www.enginatics.com/example/ap-invoice-on-hold-11i/
-- Library Link: https://www.enginatics.com/reports/ap-invoice-on-hold-11i/
-- Run Report: https://demo.enginatics.com/
select /*+ push_pred(y) */
x.ledger,
x.operating_unit,
x.c_hold_type hold_type,
x.c_nls_hold_code hold_name,
x.c_hold_code hold_code,
x.c_nls_hold_desc "Hold Description",
x.c_postable "Accounting Allowed",
x.c_batch_name batch_name,
x.c_vendor_name vendor,
x.c_vendor_site vendor_site,
x.c_invoice_num invoice_number,
x.po_number,
(select gps.period_name
from gl_period_statuses gps
where gps.set_of_books_id = x.set_of_books_id
and gps.application_id = 200
and gps.adjustment_period_flag = 'N'
and x.c_invoice_date between gps.start_date and gps.end_date
) invoice_date_period,
x.c_invoice_date invoice_date,
x.c_original_amount held_original_amt_func_curr,
x.c_amount_remaining held_remaining_amt_func_curr,
x.c_description invoice_description,
(select gps.period_name
from gl_period_statuses gps
where gps.set_of_books_id = x.set_of_books_id
and gps.application_id = 200
and gps.adjustment_period_flag = 'N'
and trunc(x.c_inv_creation_date) between gps.start_date and gps.end_date
) invoice_creation_period,
trunc(x.c_inv_creation_date) invoice_creation_date,
y.cost_center highest_value_cost_centre,
trunc(x.payment_date) payment_date,
x.invoice_pay_group,
x.invalid_account,
to_char(x.c_invoice_date,'YYYY-MM - Mon') invoice_date_label,
to_char(x.c_inv_creation_date,'YYYY-MM - Mon') invoice_creation_date_label,
case when row_number() over (partition by x.c_invoice_id,x.c_hold_type order by x.c_hold_code) = 1
then 1
else 0
end invoice_count,
case when row_number() over (partition by x.c_invoice_id,x.c_hold_type order by x.c_hold_code) = 1
then x.c_original_amount
else null
end inv_original_amt_func_curr,
case when row_number() over (partition by x.c_invoice_id,x.c_hold_type order by x.c_hold_code) = 1
then x.c_amount_remaining
else null
end inv_remaining_amt_func_curr
from
(
select -- invoices on hold
gsob.set_of_books_id,
gsob.chart_of_accounts_id,
gsob.name ledger,
haou.name operating_unit,
v.vendor_name c_vendor_name,
v.vendor_id c_vendor_id,
vs.vendor_site_code c_vendor_site,
decode(h.hold_lookup_code, null,:c_nls_na, h.hold_lookup_code) c_hold_code,
decode(h.hold_lookup_code, null,:c_nls_na, alc.displayed_field) c_nls_hold_code,
decode(h.hold_lookup_code, null,:c_nls_na, alc.description) c_nls_hold_desc,
decode(ahc.postable_flag,'Y',:c_nls_yes,:c_nls_no) c_postable,
inv1.invoice_date c_invoice_date,
b.batch_name c_batch_name,
inv1.invoice_id c_invoice_id,
inv1.invoice_num c_invoice_num,
( select distinct
poh.segment1
from
po_line_locations poll,
po_headers poh
where
poll.line_location_id = h.line_location_id and
poll.po_header_id = poh.po_header_id
) po_number,
decode(inv1.invoice_currency_code, gsob.currency_code, inv1.invoice_amount, inv1.base_amount) c_original_amount,
decode(inv1.invoice_currency_code,
gsob.currency_code, inv1.invoice_amount,
inv1.base_amount) -
decode(inv1.payment_currency_code,
gsob.currency_code,
nvl(inv1.amount_paid,0) + nvl(discount_amount_taken,0),
decode(f.minimum_accountable_unit,
null, round(((decode(inv1.payment_cross_rate_type,
'EMU FIXED', 1/inv1.payment_cross_rate,
inv1.exchange_rate)) *
nvl(inv1.amount_paid,0)),
f.precision),
round(((decode(inv1.payment_cross_rate_type,
'EMU FIXED', 1/inv1.payment_cross_rate,
inv1.exchange_rate)) * nvl(inv1.amount_paid,0)) /
f.minimum_accountable_unit) *
f.minimum_accountable_unit) +
decode(f.minimum_accountable_unit,
null, round(((decode(inv1.payment_cross_rate_type,
'EMU FIXED', 1/inv1.payment_cross_rate,
inv1.exchange_rate)) *
nvl(inv1.discount_amount_taken,0)),
f.precision),
round(((decode(inv1.payment_cross_rate_type,
'EMU FIXED', 1/inv1.payment_cross_rate,
inv1.exchange_rate)) *
nvl(inv1.discount_amount_taken,0)) /
f.minimum_accountable_unit) *
f.minimum_accountable_unit))
c_amount_remaining,
inv1.description c_description,
'Invoice Hold' c_hold_type,
inv1.creation_date c_inv_creation_date,
inv1.pay_group_lookup_code invoice_pay_group,
(select
max(aca.check_date)
from
ap_invoice_payments_all aipa,
ap_checks_all aca
where
aipa.check_id = aca.check_id and
aca.void_date is null and
aca.stopped_date is null and
aipa.invoice_id = inv1.invoice_id
) payment_date,
case
when h.hold_lookup_code= 'DIST ACCT INVALID'
then
( select
distinct listagg(gcck.concatenated_segments,', ') within group (order by gcck.concatenated_segments)
from
ap_invoice_distributions aid,
gl_code_combinations gcc,
gl_code_combinations_kfv gcck
where
aid.invoice_id = h.invoice_id and
aid.line_type_lookup_code = 'ITEM' and
aid.dist_code_combination_id = gcc.code_combination_id (+) and
aid.dist_code_combination_id = gcck.code_combination_id (+) and
( gcc.code_combination_id is null or
gcc.detail_posting_allowed_flag = 'N' or
trunc(gcc.start_date_active) > aid.accounting_date or
trunc(gcc.end_date_active) < aid.accounting_date or
gcc.template_id is not null or
gcc.enabled_flag <> 'Y' or
gcc.summary_flag <>'N'
)
)
else
null
end invalid_account
from
gl_sets_of_books gsob,
hr_all_organization_units haou,
po_vendors v,
po_vendor_sites vs,
ap_invoices inv1,
ap_batches_all b,
ap_payment_schedules s,
ap_holds h,
ap_hold_codes ahc,
ap_lookup_codes alc,
fnd_currencies_vl f
where
2=2
and v.vendor_id = inv1.vendor_id
and gsob.set_of_books_id = inv1.set_of_books_id
and haou.organization_id = inv1.org_id
and vs.vendor_id (+) = inv1.vendor_id
and vs.vendor_site_id (+) = inv1.vendor_site_id
and h.invoice_id = inv1.invoice_id
and b.batch_id(+) = inv1.batch_id
and s.invoice_id(+) = inv1.invoice_id
and h.release_lookup_code is null
and f.currency_code = gsob.currency_code
and alc.lookup_type = 'HOLD CODE'
and alc.lookup_code = h.hold_lookup_code
and ahc.hold_lookup_code = h.hold_lookup_code
union
select -- payments on hold
gsob.chart_of_accounts_id,
gsob.set_of_books_id,
gsob.name ledger,
haou.name operating_unit,
v.vendor_name c_vendor_name,
v.vendor_id c_vendor_id,
vs.vendor_site_code c_vendor_site,
:c_nls_na c_hold_code,
'Scheduled Payment Hold' c_nls_hold_code,
:c_nls_na c_nls_hold_desc,
:c_nls_na c_postable,
inv1.invoice_date c_invoice_date,
b.batch_name c_batch_name,
inv1.invoice_id c_nr_invoice_id,
inv1.invoice_num c_invoice_num,
null po_number,
decode(inv1.invoice_currency_code, gsob.currency_code, inv1.invoice_amount, inv1.base_amount) c_original_amount,
decode(inv1.invoice_currency_code, gsob.currency_code, inv1.invoice_amount,inv1.base_amount) -
decode(inv1.payment_currency_code,
gsob.currency_code,
nvl(inv1.amount_paid,0) + nvl(discount_amount_taken,0),
decode(f.minimum_accountable_unit,
null, round(((decode(inv1.payment_cross_rate_type,
'EMU FIXED', 1/inv1.payment_cross_rate,
inv1.exchange_rate)) *
nvl(inv1.amount_paid,0)),
f.precision),
round(((decode(inv1.payment_cross_rate_type,
'EMU FIXED', 1/inv1.payment_cross_rate,
inv1.exchange_rate)) * nvl(inv1.amount_paid,0)) /
f.minimum_accountable_unit) *
f.minimum_accountable_unit) +
decode(f.minimum_accountable_unit,
null, round(((decode(inv1.payment_cross_rate_type,
'EMU FIXED', 1/inv1.payment_cross_rate,
inv1.exchange_rate)) *
nvl(inv1.discount_amount_taken,0)),
f.precision),
round(((decode(inv1.payment_cross_rate_type,
'EMU FIXED', 1/inv1.payment_cross_rate,
inv1.exchange_rate)) *
nvl(inv1.discount_amount_taken,0)) /
f.minimum_accountable_unit) *
f.minimum_accountable_unit)) c_amount_remaining,
'Scheduled Payment Hold' c_description,
'Scheduled Payment Hold' c_hold_type,
inv1.creation_date c_inv_creation_date,
inv1.pay_group_lookup_code invoice_pay_group,
(select
max(aca.check_date)
from
ap_invoice_payments_all aipa,
ap_checks_all aca
where
aipa.check_id = aca.check_id and
aca.void_date is null and
aca.stopped_date is null and
aipa.invoice_id = inv1.invoice_id
) payment_date,
null invalid_account
from
gl_sets_of_books gsob,
hr_all_organization_units haou,
po_vendors v,
po_vendor_sites vs,
ap_invoices inv1,
ap_batches_all b,
ap_payment_schedules s,
fnd_currencies_vl f
where
2=2
and v.vendor_id = inv1.vendor_id
and gsob.set_of_books_id = inv1.set_of_books_id
and haou.organization_id = inv1.org_id
and vs.vendor_id (+) = inv1.vendor_id
and vs.vendor_site_id (+) = inv1.vendor_site_id
and b.batch_id(+) = inv1.batch_id
and s.invoice_id = inv1.invoice_id
and s.hold_flag = 'Y'
and f.currency_code = gsob.currency_code
union
select -- vendor sites on hold
gsob.set_of_books_id,
gsob.chart_of_accounts_id,
gsob.name ledger,
haou.name operating_unit,
v.vendor_name c_vendor_name,
v.vendor_id c_vendor_id,
vs.vendor_site_code c_vendor_site,
:c_nls_na c_hold_code,
'Supplier Site Hold' c_nls_hold_code,
:c_nls_na c_nls_hold_desc,
:c_nls_na c_postable,
inv1.invoice_date c_invoice_date,
b.batch_name c_batch_name,
inv1.invoice_id c_invoice_id,
inv1.invoice_num c_invoice_num,
null po_number,
decode(inv1.invoice_currency_code, gsob.currency_code, inv1.invoice_amount, inv1.base_amount) c_original_amount,
decode(inv1.invoice_currency_code,gsob.currency_code, inv1.invoice_amount,inv1.base_amount) -
decode(inv1.payment_currency_code,
gsob.currency_code,
nvl(inv1.amount_paid,0) + nvl(discount_amount_taken,0),
decode(f.minimum_accountable_unit,
null, round(((decode(inv1.payment_cross_rate_type,
'EMU FIXED', 1/inv1.payment_cross_rate,
inv1.exchange_rate)) *
nvl(inv1.amount_paid,0)),
f.precision),
round(((decode(inv1.payment_cross_rate_type,
'EMU FIXED', 1/inv1.payment_cross_rate,
inv1.exchange_rate)) * nvl(inv1.amount_paid,0)) /
f.minimum_accountable_unit) *
f.minimum_accountable_unit) +
decode(f.minimum_accountable_unit,
null, round(((decode(inv1.payment_cross_rate_type,
'EMU FIXED', 1/inv1.payment_cross_rate,
inv1.exchange_rate)) *
nvl(inv1.discount_amount_taken,0)),
f.precision),
round(((decode(inv1.payment_cross_rate_type,
'EMU FIXED', 1/inv1.payment_cross_rate,
inv1.exchange_rate)) *
nvl(inv1.discount_amount_taken,0)) /
f.minimum_accountable_unit) *
f.minimum_accountable_unit)) c_amount_remaining,
inv1.description c_description,
'Supplier Site Hold' c_hold_type,
inv1.creation_date c_inv_creation_date,
inv1.pay_group_lookup_code invoice_pay_group,
(select
max(aca.check_date)
from
ap_invoice_payments_all aipa,
ap_checks_all aca
where
aipa.check_id = aca.check_id and
aca.void_date is null and
aca.stopped_date is null and
aipa.invoice_id = inv1.invoice_id
) payment_date,
null invalid_account
from
gl_sets_of_books gsob,
hr_all_organization_units haou,
po_vendors v,
po_vendor_sites vs,
ap_invoices inv1,
ap_batches_all b,
ap_payment_schedules s,
fnd_currencies_vl f
where
2=2
and gsob.set_of_books_id = inv1.set_of_books_id
and haou.organization_id = inv1.org_id
and v.vendor_id (+) = inv1.vendor_id
and vs.vendor_id (+) = inv1.vendor_id
and vs.vendor_site_id (+) = inv1.vendor_site_id
and b.batch_id(+) = inv1.batch_id
and s.invoice_id(+) = inv1.invoice_id
and vs.hold_all_payments_flag = 'Y'
and f.currency_code = gsob.currency_code
and inv1.cancelled_date is null
and inv1.payment_status_flag != 'Y'
) x,
(select distinct
y.invoice_id,
first_value(y.cctr) over (partition by y.invoice_id order by y.amount desc, y.cctr rows between unbounded preceding and unbounded following) cost_center
from
(select
aid.invoice_id,
fnd_flex_xml_publisher_apis.process_kff_combination_1('acct_flex_cost_seg','SQLGL','GL#',gcc.chart_of_accounts_id,null,gcc.code_combination_id,'FA_COST_CTR','Y','VALUE') cctr,
sum(amount) amount
from
ap_invoice_distributions aid,
po_distributions pd,
gl_code_combinations gcc
where
aid.line_type_lookup_code != 'TAX' and
aid.po_distribution_id = pd.po_distribution_id (+) and
nvl(pd.code_combination_id,aid.dist_code_combination_id) = gcc.code_combination_id
group by
aid.invoice_id,
fnd_flex_xml_publisher_apis.process_kff_combination_1('acct_flex_cost_seg','SQLGL','GL#',gcc.chart_of_accounts_id,null,gcc.code_combination_id,'FA_COST_CTR','Y','VALUE')
) y
) y
where
1=1 and
x.c_invoice_id = y.invoice_id (+)
order by
decode(:p_order_by, 'Hold Name',c_nls_hold_code,x.c_vendor_name)
,x.c_vendor_name
,x.c_vendor_site
,x.c_invoice_date
,x.c_invoice_num
,x.c_nls_hold_code