[Home] [Help]
PACKAGE BODY: APPS.PSA_FUNDS_CHECKER_PKG
Source
1 PACKAGE BODY PSA_FUNDS_CHECKER_PKG AS
2 /* $Header: psafbcfb.pls 120.121.12020000.2 2012/10/29 17:18:07 sasukuma ship $ */
3
4
5
6 /*=============================================================================+
7 | SegNamArray : contains all Active Segments |
8 | TokNameArray : contains names of all tokens |
9 | TokValArray : contains values for all tokens |
10 | g_delim : Used as a delimiter in the Debug Info String |
11 | seg_name : Active Segments |
12 | seg_val : Segment Values. This is typecast to the |
13 | definition in the Flex Package FND_FLEX_EXT |
14 | msg_tok_names : Message Token Name |
15 | msg_tok_val : Message Token Value |
16 | g_num_segs : Number of active segments |
17 | g_acct_seg_index : Accounting Segment Index |
18 | g_ledger_id : Ledger Id |
19 | g_packet_id : Packet ID for the Packet being processed |
20 | g_fcmode : Operation Mode. Valid Modes are : |
21 | 'C' for Funds Check (partial), |
22 | 'R' for Funds Reservation, |
23 | 'A' for Funds Adjustment which is identical |
24 | to Funds Reservation except for the |
25 | difference in Messages, |
26 | 'F' for Force Pass |
27 | 'U' for Unreservation & |
28 | 'P' for Partial Reservation |
29 | 'M' for Funds Check (Full Mode) |
30 | g_partial_resv_flag : Whether Partial Reservation is allowed |
31 | g_return_code : Funds Check Return Code for the Packet |
32 | processed. Valid Return Codes are : |
33 | 'S' for Success, |
34 | 'A' for Advisory, |
35 | 'F' for Failure, |
36 | 'P' for Partial, |
37 | 'F' for Force Pass & |
38 | 'T' for Fatal |
39 | gms_retcode : Funds Check Return code for grants processing |
40 | g_psa_grantcheck : Is GMS Enabled |
41 | g_psa_pacheck : Is PA Enabled |
42 | g_cbc_enabled : Is CBC Enabled |
43 | g_packet_id_ursvd : ID of the Packet being unreserved |
44 | g_ussgl_option_flag : Whether the USSGL Option is Enabled |
45 | g_budgetary_enc_flag : Whether to default Automatic Encumbrance Flag |
46 | to 'Y' for Budgetary Encumbrances Transactions |
47 | g_user_id : AOL User Id |
48 | g_resp_appl_id : Calling Application Id |
49 | g_user_resp_id : User Responsibility Id |
50 | g_conc_flag : Whether invoked from a concurrent process |
51 | g_calling_prog_flag : Which module invoked the call. Valid values : |
52 | 'G' for General Ledger & |
53 | 'S' for Subledger via SLA |
54 | g_override_flag : Override Transaction if it fails Funds Check |
55 | g_bc_option_id : Budgetary Control Option assigned to the User |
56 | g_coa_id : Flex Num for the Accounting Flexfield Structure |
57 | g_func_curr_code : Functional Currency Code |
58 | g_append_je_flag : Whether there are associated Journal Entry lines |
59 | to be appended, created or deleted |
60 | g_summarized_flag : Whether there are Summary Transactions in the |
61 | Packet |
62 | g_arrival_seq : Arrival Sequence Number of the Packet in process |
63 | g_no_msg_tokens : Number of messages tokens |
64 | g_reverse_tc_flag : Profile GL_REVERSE_TC_OPTION |
65 | g_enable_efc_flag : Profile PSA_ENABLE_EFC |
66 | g_fv_prepay_prof : FV profile option |
67 | g_debug : Global Variable used for debugging purpose |
68 | g_xla_debug : Global Variable used for SLA debugging purpose |
69 | g_overlapping_budget : Check if there are multiple overlapping budgets |
70 | for the account |
71 | g_session_id : Current Session Identifier |
72 | g_serial_id : Current Session Serial# Identifier |
73 +=============================================================================*/
74
75 TYPE SegNamArray IS TABLE OF VARCHAR2(9) INDEX BY BINARY_INTEGER;
76
77 TYPE TokNameArray IS TABLE OF VARCHAR2(15) INDEX BY BINARY_INTEGER;
78
79 TYPE TokValArray IS TABLE OF VARCHAR2(1000) INDEX BY BINARY_INTEGER;
80
81 g_delim CONSTANT VARCHAR2(1) := '[';
82
83 seg_name SegNamArray;
84
85 seg_val FND_FLEX_EXT.SegmentArray;
86
87 msg_tok_names TokNameArray;
88
89 msg_tok_val TokValArray;
90
91 g_num_segs NUMBER;
92
93 g_acct_seg_index NUMBER;
94
95 g_ledger_id gl_bc_packets.ledger_id%TYPE;
96
97 g_packet_id gl_bc_packets.packet_id%TYPE;
98
99 g_fcmode VARCHAR2(1);
100
101 g_partial_resv_flag VARCHAR2(1);
102
103 g_return_code gl_bc_packets.result_code%TYPE;
104
105 gms_retcode gl_bc_packets.result_code%TYPE;
106
107 g_psa_grantcheck BOOLEAN;
108
109 g_psa_pacheck BOOLEAN;
110
111 g_cbc_enabled BOOLEAN;
112
113 g_cbc_retcode NUMBER;
114
115 g_packet_id_ursvd gl_bc_packets.packet_id%TYPE;
116
117 g_ussgl_option_flag BOOLEAN;
118
119 g_budgetary_enc_flag VARCHAR2(1);
120
121 g_user_id fnd_user.user_id%TYPE;
122
123 g_resp_appl_id fnd_application.application_id%TYPE;
124
125 g_user_resp_id fnd_responsibility.responsibility_id%TYPE;
126
127 g_conc_flag BOOLEAN;
128
129 g_calling_prog_flag VARCHAR2(1);
130
131 g_override_flag BOOLEAN;
132
133 g_bc_option_id gl_bc_options.bc_option_id%TYPE;
134
135 g_coa_id gl_ledgers_public_v.chart_of_accounts_id%TYPE;
136
137 g_func_curr_code gl_ledgers_public_v.currency_code%TYPE;
138
139 g_append_je_flag BOOLEAN;
140
141 g_summarized_flag BOOLEAN;
142
143 g_arrival_seq gl_bc_packet_arrival_order.arrival_seq%TYPE;
144
145 g_no_msg_tokens NUMBER;
146
147 g_requery_flag BOOLEAN;
148
149 g_reverse_tc_flag VARCHAR2(1) := 'Y';
150
151 g_enable_efc_flag VARCHAR2(1) := 'N';
152
153 g_fv_prepay_prof BOOLEAN := FALSE;
154
155 g_xla_debug BOOLEAN := FALSE;
156
157 g_overlapping_budget BOOLEAN;
158
159 g_session_id NUMBER;
160
161 g_serial_id NUMBER;
162
163 --===========================FND_LOG.START=====================================
164 g_state_level NUMBER := FND_LOG.LEVEL_STATEMENT;
165 g_proc_level NUMBER := FND_LOG.LEVEL_PROCEDURE;
166 g_event_level NUMBER := FND_LOG.LEVEL_EVENT;
167 g_excep_level NUMBER := FND_LOG.LEVEL_EXCEPTION;
168 g_error_level NUMBER := FND_LOG.LEVEL_ERROR;
169 g_unexp_level NUMBER := FND_LOG.LEVEL_UNEXPECTED;
170 g_path VARCHAR2(50) := 'psa.plsql.psafbcfb.psa_funds_checker_pkg.';
171 --===========================FND_LOG.END=======================================
172
173
174 /*================================+
175 | Private Function Definition |
176 +================================*/
177
178 FUNCTION glxfin(p_ledgerid IN NUMBER,
179 p_packetid IN NUMBER,
180 p_mode IN VARCHAR2,
181 p_override IN VARCHAR2,
182 p_conc_flag IN VARCHAR2,
183 p_user_id IN NUMBER,
184 p_user_resp_id IN NUMBER,
185 p_calling_prog_flag IN VARCHAR2) RETURN BOOLEAN;
186
187 FUNCTION glxfcp RETURN BOOLEAN;
188
189 FUNCTION glxfug RETURN BOOLEAN;
190
191 FUNCTION glxfkf RETURN BOOLEAN;
192
193 FUNCTION glxfiu RETURN BOOLEAN;
194
195 FUNCTION glxfss RETURN BOOLEAN;
196
197 FUNCTION glxfgb RETURN BOOLEAN;
198
199 FUNCTION glxfrc RETURN BOOLEAN;
200
201 FUNCTION glzcbc RETURN NUMBER;
202
203 FUNCTION glzgchk RETURN BOOLEAN;
204
205 FUNCTION glzpafck RETURN BOOLEAN;
206
207 FUNCTION glxfor RETURN BOOLEAN;
208
209 FUNCTION glxfrs RETURN BOOLEAN;
210
211 FUNCTION glrchk(post_control IN gl_bc_packets.result_code%TYPE) RETURN BOOLEAN;
212
213 FUNCTION glxfje RETURN BOOLEAN;
214
215 FUNCTION glxfuf RETURN BOOLEAN;
216
217 FUNCTION glxcon RETURN BOOLEAN;
218
219 PROCEDURE message_token(tokname IN VARCHAR2,
220 tokval IN VARCHAR2);
221
222 PROCEDURE add_message(appname IN VARCHAR2,
223 msgname IN VARCHAR2);
224
225 FUNCTION glxfar RETURN BOOLEAN;
226
227 FUNCTION fv_prepay_pkg RETURN BOOLEAN;
228
229 FUNCTION glurevd ( p_ledger_id NUMBER,
230 p_je_category VARCHAR2,
231 p_je_source VARCHAR2,
232 p_je_period VARCHAR2,
233 p_je_date DATE,
234 x_reversal_method OUT NOCOPY VARCHAR2,
235 p_balance_type VARCHAR2) RETURN BOOLEAN;
236
237 PROCEDURE get_session_details(x_session_id OUT NOCOPY NUMBER,
238 x_serial_id OUT NOCOPY NUMBER);
239
240 PROCEDURE init
241 IS
242 l_path_name VARCHAR2(500);
243 l_file_info VARCHAR2(2000);
244 BEGIN
245 l_path_name := g_path || '.init';
246 l_file_info := '$Header: psafbcfb.pls 120.121.12020000.2 2012/10/29 17:18:07 sasukuma ship $';
247 psa_utils.debug_other_string(g_state_level,l_path_name, 'PSA_FUNDS_CHECKER version = '||l_file_info);
248 END;
249
250
251 /* ------------------------------------------------------------------------- */
252 /* */
253 /* Funds Check API for any process that needs to perform Funds Check and/or */
254 /* Funds Reservation */
255 /* */
256 /* This routine returns TRUE if successful; otherwise, it returns FALSE */
257 /* */
258 /* In case of failure, this routine will populate the global Message Stack */
259 /* using FND_MESSAGE. The calling routine will retrieve the message from */
260 /* the Stack */
261 /* */
262 /* When invoked from a Concurrent Process, the calling process has to */
263 /* initialize values for User ID, User Responsibility ID, Calling */
264 /* Application ID and Login ID. These values should be initialized, in the */
265 /* Global Stack by invoking FND_GLOBAL, prior to calling Funds Checker */
266 /* */
267 /* External Packages which are being invoked include : */
268 /* */
269 /* FND_GLOBAL */
270 /* FND_PROFILE */
271 /* FND_INSTALLATION */
272 /* FND_MESSAGE */
273 /* FND_FLEX_EXT */
274 /* FND_FLEX_APIS */
275 /* */
276 /* GL Tables which are being used include : */
277 /* */
278 /* GL_BC_PACKETS */
279 /* GL_BC_PACKET_ARRIVAL_ORDER */
280 /* GL_BC_OPTIONS */
281 /* GL_BC_OPTION_DETAILS */
282 /* GL_BC_PERIOD_MAP */
283 /* GL_BC_DUAL */
284 /* GL_BC_DUAL2 */
285 /* GL_CONCURRENCY_CONTROL */
286 /* GL_PERIOD_STATUSES */
287 /* GL_LOOKUPS */
288 /* GL_USSGL_TRANSACTION_CODES */
289 /* GL_USSGL_ACCOUNT_PAIRS */
290 /* GL_BALANCES */
291 /* GL_BUDGETS */
292 /* GL_BUDGET_VERSIONS */
293 /* GL_BUDGET_ASSIGNMENTS */
294 /* GL_BUDGET_PERIOD_RANGES */
295 /* GL_JE_BATCHES */
296 /* GL_JE_HEADERS */
297 /* GL_JE_LINES */
298 /* GL_SETS_OF_BOOKS */
299 /* GL_CODE_COMBINATIONS */
300 /* GL_ACCOUNT_HIERARCHIES */
301 /* */
302 /* AOL Tables which are being used include : */
303 /* */
304 /* FND_USER */
305 /* FND_APPLICATION */
306 /* FND_RESPONSIBILITY */
307 /* FND_PROFILE_OPTION_VALUES */
308 /* FND_PRODUCT_INSTALLATIONS */
309 /* */
310 /* ------------------------------------------------------------------------- */
311
312 -- Parameters :
313
314 -- p_ledgerid : Set of Books ID
315
316 -- p_packetid : Packet ID
317
318 -- p_mode : Funds Checker Operation Mode. Defaults to 'C' (Checking)
319
320 -- p_override : Whether to Override in case of Funds Reservation failure
321 -- because of lack of Funds. Defaults to 'N' (No)
322
323 -- p_conc_flag : Whether invoked from a Concurrent Process. Defaults to
324 -- 'N' (No)
325
326 -- p_user_id : User ID for Override (from AP AutoApproval)
327
328 -- p_user_resp_id : User Responsibility ID for Override (from AP AutoApproval)
329
330 -- p_return_code : Return Status for the Packet
331
332 --
333 -- Overloaded Version of glxfck()
334 -- This contains an additional OUT parameter p_unrsv_packet_id.
335 -- This is to be used by General Ledger only.
336 --
337
338 FUNCTION glxfck(p_ledgerid IN NUMBER,
339 p_packetid IN NUMBER,
340 p_mode IN VARCHAR2 DEFAULT 'C',
341 p_override IN VARCHAR2 DEFAULT 'N',
342 p_conc_flag IN VARCHAR2 DEFAULT 'N',
343 p_user_id IN NUMBER DEFAULT NULL,
344 p_user_resp_id IN NUMBER DEFAULT NULL,
345 p_calling_prog_flag IN VARCHAR2 DEFAULT 'G',
346 p_return_code OUT NOCOPY VARCHAR2,
347 p_unrsv_packet_id OUT NOCOPY NUMBER) RETURN BOOLEAN IS
348
349 others EXCEPTION;
350
351 -- ========================= FND LOG ===========================
352 l_full_path VARCHAR2(100);
353 -- ========================= FND LOG ===========================
354 BEGIN
355
356 l_full_path := g_path || 'glxfck - public1';
357
358 -- ========================= FND LOG ===========================
359 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_ledgerid -> ' || p_ledgerid);
360 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_packetid -> ' || p_packetid);
361 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_mode -> ' || p_mode);
362 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_override -> ' || p_override);
363 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_conc_flag -> ' || p_conc_flag);
364 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_user_id -> ' || p_user_id);
365 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_calling_prog_flag -> ' || p_calling_prog_flag);
366 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_user_resp_id -> ' || p_user_resp_id);
367 -- ========================= FND LOG ===========================
368
369 IF NOT glxfck( p_ledgerid ,
370 p_packetid ,
371 p_mode ,
372 p_override ,
373 p_conc_flag ,
374 p_user_id ,
375 p_user_resp_id ,
376 p_calling_prog_flag ,
377 p_return_code ) THEN
378
379 -- ========================= FND LOG ===========================
380 psa_utils.debug_other_string(g_state_level,l_full_path, ' glxfck --> FALSE goto gl_error');
381 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_return_code --> ' || p_return_code);
382 -- ========================= FND LOG ===========================
383 goto gl_error;
384
385 END IF;
386
387 IF (p_return_code = 'O') THEN
388 -- ========================= FND LOG ===========================
389 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_return_code --> O goto normal_exit');
390 -- ========================= FND LOG ===========================
391
392 goto normal_exit;
393 END IF;
394
395 -- Set p_unrsv_packet_id if mode is UNRESERVATION
396 -- and g_requery_flag is not set.
397
398 IF (p_mode = 'U' AND NOT g_requery_flag) THEN
399 p_unrsv_packet_id := p_packetid;
400 -- ========================= FND LOG ===========================
401 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_unrsv_packet_id --> ' || p_unrsv_packet_id );
402 -- ========================= FND LOG ===========================
403 END IF;
404
405 -- If g_requery_flag is TRUE set p_return_code = "Q"
406 -- for calling form (MJE) to requery instead of the
407 -- regular commit. [p_return code "Q" => Success/Advisory]
408
409 IF g_requery_flag THEN
410 p_return_code := 'Q';
411 -- ========================= FND LOG ===========================
412 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_return_code --> Q => Success/Advisory ');
413 -- ========================= FND LOG ===========================
414 END IF;
415
416 <<NORMAL_EXIT>>
417
418 -- ========================= FND LOG ===========================
419 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN --> TRUE ');
420 -- ========================= FND LOG ===========================
421
422 RETURN(TRUE);
423
424 <<GL_ERROR>>
425
426 -- ========================= FND LOG ===========================
427 psa_utils.debug_other_string(g_state_level,l_full_path, ' reached gl_error label ');
428 -- ========================= FND LOG ===========================
429
430 if not glxfuf then
431 -- ========================= FND LOG ===========================
432 psa_utils.debug_other_string(g_state_level,l_full_path, ' Raise OTHERS ');
433 -- ========================= FND LOG ===========================
434 raise others;
435 end if;
436
437 -- ========================= FND LOG ===========================
438 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN --> FALSE ');
439 -- ========================= FND LOG ===========================
440
441 RETURN(FALSE);
442
443 EXCEPTION
444
445 WHEN OTHERS THEN
446 -- ========================= FND LOG ===========================
447 psa_utils.debug_other_string(g_excep_level,l_full_path, ' EXCEPTION WHEN OTHERS ' || SQLERRM);
448 -- ========================= FND LOG ===========================
449
450 message_token('PROCEDURE', 'Funds Checker');
451 message_token('EVENT', SQLERRM);
452 add_message('SQLGL', 'GL_UNHANDLED_EXCEPTION');
453
454 -- ========================= FND LOG ===========================
455 psa_utils.debug_other_string(g_excep_level,l_full_path, ' RETURN --> FALSE ');
456 -- ========================= FND LOG ===========================
457
458 return(FALSE);
459
460 END glxfck;
461
462 /* =========================== GLXFCK PRIVATE ================================= */
463
464 FUNCTION glxfck(p_ledgerid IN NUMBER,
465 p_packetid IN NUMBER,
466 p_mode IN VARCHAR2 DEFAULT 'C',
467 p_override IN VARCHAR2 DEFAULT 'N',
468 p_conc_flag IN VARCHAR2 DEFAULT 'N',
469 p_user_id IN NUMBER DEFAULT NULL,
470 p_user_resp_id IN NUMBER DEFAULT NULL,
471 p_calling_prog_flag IN VARCHAR2 DEFAULT 'S',
472 p_return_code OUT NOCOPY VARCHAR2) RETURN BOOLEAN IS
473
474 cursor det_override_reqd IS
475 select 'x'
476 from gl_bc_packets bp
477 where bp.packet_id = g_packet_id
478 and bp.result_code between 'F00' and 'F19'
479 and bp.ussgl_link_to_parent_id is null
480 and bp.template_id is null
481 and nvl(bp.override_amount, -1) >=
482 abs(nvl(bp.accounted_dr, 0) - nvl(bp.accounted_cr, 0))
483 and not exists
484 (
485 select 'If Partial Resv disallowed then all non-generated ' ||
486 'detail lines that failed with any validation errors ' ||
487 'or because of Funds Availability'
488 from gl_bc_packets pk
489 where pk.packet_id = g_packet_id
490 and pk.template_id is null
491 and pk.result_code like 'F%'
492 and ((g_partial_resv_flag = 'N'
493 and pk.ussgl_link_to_parent_id is null
494 and (pk.result_code between 'F20' and 'F29'
495 or nvl(pk.override_amount, -1) <
496 abs(nvl(pk.accounted_dr, 0) - nvl(pk.accounted_cr, 0))))
497 or (pk.ussgl_link_to_parent_id = bp.ussgl_parent_id
498 and pk.result_code between 'F20' and 'F29'))
499 );
500
501 cursor ussgl_override_reqd is
502 select 'x'
503 from gl_bc_packets bp
504 where bp.packet_id = g_packet_id
505 and bp.result_code between 'F00' and 'F19'
506 and bp.ussgl_link_to_parent_id is not null
507 and exists
508 (
509 select 'Corresp Original Transaction which was Overridden'
510 from gl_bc_packets pk
511 where pk.packet_id = g_packet_id
512 and pk.ussgl_parent_id = bp.ussgl_link_to_parent_id
513 and pk.result_code = 'P21'
514 );
515
516 l_override_reqd VARCHAR2(1);
517 others EXCEPTION;
518
519 -- ========================= FND LOG ===========================
520 l_full_path VARCHAR2(100);
521 -- ========================= FND LOG ===========================
522
523 BEGIN
524
525 l_full_path := g_path || 'glxfck - private';
526
527 -- =========================== FND LOG ===========================
528 psa_utils.debug_other_string(g_state_level,l_full_path, ' GLXFCK PRIVATE - START' );
529 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_ledgerid -> ' || p_ledgerid);
530 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_packetid -> ' || p_packetid);
531 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_mode -> ' || p_mode);
532 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_override -> ' || p_override);
533 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_conc_flag -> ' || p_conc_flag);
534 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_user_id -> ' || p_user_id);
535 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_user_resp_id -> ' || p_user_resp_id);
536 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_calling_prog_flag -> ' || p_calling_prog_flag);
537 psa_utils.debug_other_string(g_state_level,l_full_path, ' Calling glxfin ');
538 -- ========================= FND LOG =============================
539
540 if (p_calling_prog_flag = 'S' and g_fcmode = 'U') then
541 -- =========================== FND LOG ===========================
542 psa_utils.debug_other_string(g_state_level,l_full_path, ' Calling Program = S and mode = Unreservation so return without processing. RETURN -> TRUE.' );
543 -- =========================== FND LOG ===========================
544 -- Since we will not be supporting unreservation functionality for SLA
545 -- return back.
546 return true;
547 end if;
548
549 -- =========================== FND LOG ===========================
550 psa_utils.debug_other_string(g_state_level,l_full_path, ' Calling glxfin - initialization ' );
551 -- =========================== FND LOG ===========================
552
553 -- Initialize Global Variables
554 if not glxfin(p_ledgerid => p_ledgerid,
555 p_packetid => p_packetid,
556 p_mode => p_mode,
557 p_override => p_override,
558 p_conc_flag => p_conc_flag,
559 p_user_id => p_user_id,
560 p_user_resp_id => p_user_resp_id,
561 p_calling_prog_flag => p_calling_prog_flag) then
562
563 -- =========================== FND LOG ===========================
564 psa_utils.debug_other_string(g_state_level,l_full_path, ' glxfin --> RETURN FALSE -> goto fatal_error');
565 -- ========================= FND LOG =============================
566
567 goto fatal_error;
568 end if;
569
570 -- =========================== FND LOG ===========================
571 psa_utils.debug_other_string(g_state_level,l_full_path, ' Calling glxfcp - preprocessor ');
572 -- ========================= FND LOG =============================
573
574 -- Funds Check Processor
575 if not glxfcp then
576 -- =========================== FND LOG ===========================
577 psa_utils.debug_other_string(g_state_level,l_full_path, ' glxfcp --> RETURN FALSE -> goto fatal_error');
578 -- ========================= FND LOG =============================
579 goto fatal_error;
580 end if;
581
582
583 if g_overlapping_budget=TRUE then
584 -- =========================== FND LOG ===========================
585 psa_utils.debug_other_string(g_state_level,l_full_path, ' return_code --> F');
586 -- ========================= FND LOG =============================
587
588 p_return_code := 'F';
589
590 -- =========================== FND LOG ===========================
591 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN --> TRUE ');
592 -- ========================= FND LOG =============================
593 return(TRUE);
594
595 end if ;
596
597
598 -- Override Transactions
599 if g_override_flag and g_calling_prog_flag = 'G' and not g_conc_flag then
600
601 -- =========================== FND LOG ===========================
602 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_override_flag --> TRUE ');
603 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_calling_prog_flag --> G ');
604 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_conc_flag --> FALSE ');
605 -- ========================= FND LOG =============================
606
607 open det_override_reqd;
608 fetch det_override_reqd INTO l_override_reqd;
609
610 if (det_override_reqd%NOTFOUND) then
611
612 -- =========================== FND LOG ===========================
613 psa_utils.debug_other_string(g_state_level,l_full_path, ' det_override_reqd%NOTFOUND ');
614 -- ========================= FND LOG =============================
615
616 open ussgl_override_reqd;
617 fetch ussgl_override_reqd INTO l_override_reqd;
618
619 if (ussgl_override_reqd%FOUND) then
620
621 -- =========================== FND LOG ===========================
622 psa_utils.debug_other_string(g_state_level,l_full_path, ' ussgl_override_reqd%FOUND ');
623 -- ========================= FND LOG =============================
624
625 g_return_code := 'O';
626 goto normal_exit;
627 end if;
628
629 else
630
631 -- =========================== FND LOG ===========================
632 psa_utils.debug_other_string(g_state_level,l_full_path, ' det_override_reqd%FOUND ');
633 -- ========================= FND LOG =============================
634
635 g_return_code := 'O';
636 goto normal_exit;
637 end if;
638
639 end if;
640
641 -- =========================== FND LOG ===========================
642 psa_utils.debug_other_string(g_state_level,l_full_path, ' Calling glxcon ');
643 -- ========================= FND LOG =============================
644
645 -- Set Result Codes, Return Code, Append Journal Logic
646 if not glxcon then
647 -- =========================== FND LOG ===========================
648 psa_utils.debug_other_string(g_state_level,l_full_path, ' glxcon --> RETURN FALSE -> goto fatal_error');
649 -- ========================= FND LOG =============================
650 goto fatal_error;
651 end if;
652
653 -- =========================== FND LOG ===========================
654 psa_utils.debug_other_string(g_state_level,l_full_path, ' Calling glrchk ');
655 -- ========================= FND LOG =============================
656
657 if not glrchk('X') then
658 -- =========================== FND LOG ===========================
659 psa_utils.debug_other_string(g_state_level,l_full_path, ' glrchk --> RETURN FALSE -> goto fatal_error');
660 -- ========================= FND LOG =============================
661 goto fatal_error;
662 end if;
663
664 <<NORMAL_EXIT>>
665
666 IF (det_override_reqd%ISOPEN) THEN
667 close det_override_reqd;
668 END IF;
669
670 IF (ussgl_override_reqd%ISOPEN) THEN
671 close ussgl_override_reqd;
672 END IF;
673
674 -- =========================== FND LOG ===========================
675 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_return_code --> ' || g_return_code);
676 -- ========================= FND LOG =============================
677
678 p_return_code := g_return_code;
679
680 -- =========================== FND LOG ===========================
681 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN --> TRUE ');
682 -- ========================= FND LOG =============================
683
684 return(TRUE);
685
686
687 <<fatal_error>>
688
689 -- =========================== FND LOG ===========================
690 psa_utils.debug_other_string(g_state_level,l_full_path, ' Reached FATAL ERROR LABEL ');
691 -- ========================= FND LOG =============================
692
693 if not glxfuf then
694 -- =========================== FND LOG ===========================
695 psa_utils.debug_other_string(g_state_level,l_full_path, ' glxfuf --> RETURN FALSE -> RAISE OTHERS');
696 -- ========================= FND LOG =============================
697 raise others;
698 end if;
699
700 -- =========================== FND LOG ===========================
701 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN -> FALSE ');
702 -- ========================= FND LOG =============================
703
704 return(FALSE);
705
706 EXCEPTION
707
708 WHEN OTHERS THEN
709 -- =========================== FND LOG ===========================
710 psa_utils.debug_other_string(g_excep_level,l_full_path, ' EXCEPTION WHEN OTHERS ' || SQLERRM);
711 psa_utils.debug_other_string(g_excep_level,l_full_path, ' RETURN -> FALSE ');
712 -- ========================= FND LOG =============================
713
714 message_token('PROCEDURE', 'Funds Checker');
715 message_token('EVENT', SQLERRM);
716 add_message('SQLGL', 'GL_UNHANDLED_EXCEPTION');
717
718 return(FALSE);
719
720 END glxfck;
721
722 /* ================================ GLXFIN ================================ */
723
724 -- Initialize Global Variables
725
726 FUNCTION glxfin(p_ledgerid IN NUMBER,
727 p_packetid IN NUMBER,
728 p_mode IN VARCHAR2,
729 p_override IN VARCHAR2,
730 p_conc_flag IN VARCHAR2,
731 p_user_id IN NUMBER,
732 p_user_resp_id IN NUMBER,
733 p_calling_prog_flag IN VARCHAR2) RETURN BOOLEAN IS
734
735 i BINARY_INTEGER;
736 l_status fnd_product_installations.status%TYPE;
737 l_industry fnd_profile_option_values.profile_option_value%TYPE;
738 l_value fnd_profile_option_values.profile_option_value%TYPE;
739 l_reverse_tc_flag fnd_profile_option_values.profile_option_value%TYPE;
740 l_fv_prepay_prof fnd_profile_option_values.profile_option_value%TYPE;
741 l_fv_prepay_defined BOOLEAN;
742 l_defined BOOLEAN;
743 l_reverse_tc_defined BOOLEAN;
744
745 l_pa_status VARCHAR2(1);
746 l_pa_enabled INTEGER;
747
748 l_gms_status VARCHAR2(1);
749 l_gms_enabled INTEGER;
750
751 l_efc_status VARCHAR2(1);
752 l_efc_enabled VARCHAR2(1);
753 l_cbc_enabled VARCHAR2(1);
754
755 l_igi_status VARCHAR2(1);
756
757 l_prepare_stmt VARCHAR2(2000);
758
759 CURSOR set_of_books is
760 SELECT chart_of_accounts_id,
761 currency_code
762 FROM gl_ledgers_public_v
763 WHERE ledger_id = g_ledger_id;
764
765 others EXCEPTION;
766
767 -- ========================= FND LOG ===========================
768 l_full_path VARCHAR2(100);
769 -- ========================= FND LOG ===========================
770 BEGIN
771
772 l_full_path := g_path || 'glxfin';
773
774 -- =========================== FND LOG ===========================
775 psa_utils.debug_other_string(g_state_level,l_full_path, ' GLXFIN - START' );
776 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_ledgerid -> ' || p_ledgerid);
777 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_packetid -> ' || p_packetid);
778 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_mode -> ' || p_mode);
779 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_override -> ' || p_override);
780 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_conc_flag -> ' || p_conc_flag);
781 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_user_id -> ' || p_user_id);
782 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_user_resp_id -> ' || p_user_resp_id);
783 -- ========================= FND LOG =============================
784
785 g_psa_pacheck := FALSE;
786 g_psa_grantcheck := FALSE;
787 g_cbc_enabled := FALSE;
788 g_summarized_flag := FALSE;
789 g_append_je_flag := FALSE;
790 g_requery_flag := FALSE;
791 g_ussgl_option_flag := FALSE;
792 g_overlapping_budget := FALSE; -- Used When there are multiple overlapping budgets for the account
793
794
795 -- =========================== FND LOG ===========================
796 psa_utils.debug_other_string(g_state_level,l_full_path, ' SETTING VARIABLES ' );
797 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_psa_pacheck -> FALSE');
798 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_psa_grantcheck -> FALSE');
799 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_cbc_enabled -> FALSE');
800 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_summarized_flag -> FALSE');
801 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_append_je_flag -> FALSE');
802 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_requery_flag -> FALSE');
803 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_ussgl_option_flag -> FALSE');
804 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_overlapping_budget -> FALSE');
805 -- ========================= FND LOG =============================
806
807 /*===========================================+
808 | Assign Parameters to Global Variables |
809 +===========================================*/
810
811 g_ledger_id := p_ledgerid;
812 g_packet_id := p_packetid;
813 g_fcmode := p_mode;
814
815 -- ========================= FND LOG =============================
816 psa_utils.debug_other_string(g_state_level,l_full_path, 'Calling Get_Session_Details to fetch session variables');
817 -- ========================= FND LOG =============================
818
819 Get_Session_Details(g_session_id, g_serial_id);
820
821 -- ========================= FND LOG =============================
822 psa_utils.debug_other_string(g_state_level,l_full_path, 'Session_Id = '||g_session_id);
823 psa_utils.debug_other_string(g_state_level,l_full_path, 'Serial_Id = '||g_serial_id);
824 -- ========================= FND LOG =============================
825
826 IF p_calling_prog_flag IN ('P', 'H') THEN
827 -- ========================= FND LOG =============================
828 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_calling_prog_flag = P or H -> g_calling_prog_flag = S');
829 -- ========================= FND LOG =============================
830
831 g_calling_prog_flag := 'S';
832 ELSE
833 -- ========================= FND LOG =============================
834 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_calling_prog_flag != P or H -> g_calling_prog_flag = ' || p_calling_prog_flag);
835 -- ========================= FND LOG =============================
836
837 g_calling_prog_flag := p_calling_prog_flag;
838 END IF;
839
840 IF g_fcmode ='C' THEN -- Funds Check Partial Mode Check
841 -- ========================= FND LOG =====================================
842 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_fcmode = C -> g_partial_resv_flag = Y');
843 -- ========================= FND LOG =====================================
844
845 g_partial_resv_flag := 'Y';
846 ELSIF g_fcmode = 'M' THEN -- Funds Check Full Mode Check
847 -- ========================= FND LOG =====================================
848 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_fcmode = M -> g_partial_resv_flag = N');
849 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_fcmode = M -> g_fcmode = C');
850 -- ========================= FND LOG =====================================
851
852 g_partial_resv_flag := 'N';
853 g_fcmode := 'C';
854 ELSIF g_fcmode = 'P' THEN -- Funds Reserve Partial Mode Check
855 -- ========================= FND LOG =====================================
856 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_fcmode = P -> g_partial_resv_flag = Y');
857 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_fcmode = P -> g_fcmode = R');
858 -- ========================= FND LOG =====================================
859 --Modified by sthota for Bug 9086735
860 g_partial_resv_flag := 'N';
861 g_fcmode := 'R';
862 ELSE
863 -- ========================= FND LOG =====================================
864 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_fcmode != C, M and P -> g_partial_resv_flag = N');
865 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_fcmode -> '||g_fcmode);
866 -- ========================= FND LOG =====================================
867
868 g_partial_resv_flag := 'N';
869 END IF;
870
871 -- =========================== FND LOG ===========================
872 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_ledger_id -> ' || g_ledger_id);
873 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_packet_id -> ' || g_packet_id);
874 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_fcmode -> ' || g_fcmode);
875 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_partial_resv_flag -> '|| g_partial_resv_flag);
876 -- ========================= FND LOG =============================
877
878 /*========================+
879 | Set Overrides Flag |
880 +========================*/
881
882 if (p_override = 'N') then
883 -- =========================== FND LOG ===========================
884 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_override = N -> g_override_flag = FALSE');
885 -- =========================== FND LOG ===========================
886
887 g_override_flag := FALSE;
888 else
889 -- =========================== FND LOG ===========================
890 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_override != N -> g_override_flag = TRUE');
891 -- =========================== FND LOG ===========================
892
893 g_override_flag := TRUE;
894 end if;
895
896 /*========================+
897 | Get AOL User ID |
898 +========================*/
899
900 if ((g_override_flag) and
901 (p_user_id is not null)) then
902 g_user_id := p_user_id;
903 else
904 g_user_id := FND_GLOBAL.USER_ID;
905 end if;
906
907 -- =========================== FND LOG ===========================
908 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_user_id -> ' || g_user_id);
909 -- ========================= FND LOG =============================
910
911 if g_user_id = -1 then
912 message_token('PROCEDURE', 'Funds Checker');
913 add_message('SQLGL', 'GL_INVALID_USERID');
914 -- =========================== FND LOG ===========================
915 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN -> FALSE');
916 -- ========================= FND LOG =============================
917 g_debug := g_debug||' GLXFIN Failed : G_USER_ID = -1';
918 return(FALSE);
919 end if;
920
921 /*==============================+
922 | Get Calling Application ID |
923 +==============================*/
924
925 g_resp_appl_id := FND_GLOBAL.resp_appl_id;
926
927 if g_resp_appl_id = -1 then
928 g_resp_appl_id := 101;
929 end if;
930
931 -- =========================== FND LOG ===========================
932 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_resp_appl_id -> ' || g_resp_appl_id);
933 -- ========================= FND LOG =============================
934
935 /*=========================+
936 | Get Responsibility ID |
937 +=========================*/
938
939 if ((g_override_flag) and
940 (p_user_resp_id is not null)) then
941 g_user_resp_id := p_user_resp_id;
942 else
943 g_user_resp_id := FND_GLOBAL.RESP_ID;
944 end if;
945
946 -- =========================== FND LOG ===========================
947 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_user_resp_id -> ' || g_user_resp_id);
948 -- ========================= FND LOG =============================
949
950 if g_user_resp_id = -1 then
951 message_token('PROCEDURE', 'Funds Checker');
952 add_message('SQLGL', 'GL_INVALID_RESPID');
953 -- =========================== FND LOG ===========================
954 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN -> FALSE');
955 -- ========================= FND LOG =============================
956 g_debug := g_debug||' GLXFIN Failed : G_USER_RESP_ID = -1';
957 return(FALSE);
958 end if;
959
960 /*========================================+
961 | Whether invoked from a Batch Process |
962 +========================================*/
963
964
965 if (p_conc_flag = 'N') then
966 g_conc_flag := FALSE;
967 else
968 g_conc_flag := TRUE;
969 end if;
970
971 -- =========================== FND LOG ===========================
972 IF (g_conc_flag) THEN
973 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_conc_flag -> TRUE');
974 ELSE
975 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_conc_flag -> FALSE');
976 END IF;
977 -- ========================= FND LOG =============================
978
979 IF g_calling_prog_flag = 'G' THEN
980
981 -- Get GL Installation Info
982 -- The installation info is now implemented as a profile option (INDUSTRY).
983
984 FND_PROFILE.GET_SPECIFIC('INDUSTRY',
985 g_user_id,
986 g_user_resp_id,
987 g_resp_appl_id,
988 l_industry,
989 l_defined);
990
991 -- =========================== FND LOG ===========================
992 psa_utils.debug_other_string(g_state_level,l_full_path, ' Getting INDUSTRY details ');
993 -- ========================= FND LOG =============================
994
995 if not l_defined then
996 if not FND_INSTALLATION.GET(g_resp_appl_id,
997 101,
998 l_status,
999 l_industry) then
1000
1001 message_token('ROUTINE', 'Funds Checker');
1002 add_message('SQLGL', 'GL_CANT_GET_INSTALL_INDUSTRY');
1003 -- =========================== FND LOG ===========================
1004 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN -> FALSE');
1005 -- ========================= FND LOG =============================
1006 g_debug := g_debug||' GLXFIN Failed : Oracle General Ledger
1007 was unable to get installation industry from Funds Checker.
1008 Contact your system administrator.';
1009 return(FALSE);
1010 end if;
1011 end if;
1012
1013
1014 -- Check for Profiles if Government Install
1015
1016 -- =========================== FND LOG ===========================
1017 psa_utils.debug_other_string(g_state_level,l_full_path, ' l_industry -> ' || l_industry);
1018 -- ========================= FND LOG =============================
1019
1020 if l_industry = 'G' then
1021
1022 FND_PROFILE.GET('USSGL_OPTION', l_value);
1023
1024 if l_value is null then
1025 -- =========================== FND LOG ===========================
1026 psa_utils.debug_other_string(g_state_level,l_full_path, ' RAISE OTHERS');
1027 -- ========================= FND LOG =============================
1028 raise others;
1029 end if;
1030
1031 -- =========================== FND LOG ===========================
1032 psa_utils.debug_other_string(g_state_level,l_full_path, ' USSGL_OPTION, l_value -> ' || l_Value);
1033 -- ========================= FND LOG =============================
1034
1035 if l_value = 'Y' then
1036 -- =========================== FND LOG ===========================
1037 psa_utils.debug_other_string(g_state_level,l_full_path, ' G_USSGL_OPTION_FLAG -> TRUE ');
1038 -- ========================= FND LOG =============================
1039 g_ussgl_option_flag := TRUE;
1040 end if;
1041
1042 if g_ussgl_option_flag then
1043
1044 FND_PROFILE.GET_SPECIFIC('FV_SPLIT_INV_DISTRIBUTION_PREPAY',
1045 g_user_id,
1046 g_user_resp_id,
1047 g_resp_appl_id,
1048 l_fv_prepay_prof,
1049 l_fv_prepay_defined);
1050
1051 -- =========================== FND LOG ===========================
1052 psa_utils.debug_other_string(g_state_level,l_full_path, ' l_fv_prepay_prof -> ' || l_fv_prepay_prof);
1053 -- ========================= FND LOG =============================
1054
1055 if l_fv_prepay_prof = 'Y' then
1056 g_fv_prepay_prof := TRUE;
1057 else
1058 g_fv_prepay_prof := FALSE;
1059 end if;
1060
1061 -- =========================== FND LOG ===========================
1062 IF (g_fv_prepay_prof) THEN
1063 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_fv_prepay_prof -> TRUE');
1064 ELSE
1065 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_fv_prepay_prof -> FALSE');
1066 END IF;
1067 -- ========================= FND LOG =============================
1068
1069 end if;
1070
1071 -- Bug 678604
1072 FND_PROFILE.GET_SPECIFIC('GL_REVERSE_TC_OPTION',
1073 g_user_id,
1074 g_user_resp_id,
1075 g_resp_appl_id,
1076 l_reverse_tc_flag,
1077 l_reverse_tc_defined);
1078
1079 if not l_reverse_tc_defined then
1080 g_reverse_tc_flag := 'Y';
1081 else
1082 g_reverse_tc_flag := l_reverse_tc_flag;
1083 end if;
1084
1085 -- =========================== FND LOG ===========================
1086 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_reverse_tc_flag -> ' || g_reverse_tc_flag);
1087 -- ========================= FND LOG =============================
1088
1089 end if; -- l_industry = 'G'
1090
1091 end if; -- g_calling_prog_flag = 'G'
1092
1093
1094 /*
1095 FND_PROFILE.GET('CREATE_BUDGETARY_ENCUMBRANCES', l_value);
1096
1097 -- =========================== FND LOG ===========================
1098 psa_utils.debug_other_string(g_state_level,l_full_path, ' CBE - l_value -> ' || l_Value);
1099 -- ========================= FND LOG =============================
1100
1101 if l_value is null then
1102 -- =========================== FND LOG ===========================
1103 psa_utils.debug_other_string(g_state_level,l_full_path, ' l_value is null -> raise others');
1104 -- ========================= FND LOG =============================
1105
1106 raise others;
1107 else
1108 -- =========================== FND LOG ===========================
1109 psa_utils.debug_other_string(g_state_level,l_full_path, ' l_value not null -> g_budgetary_enc_flag = l_value = ' || l_value);
1110 -- ========================= FND LOG =============================
1111
1112 g_budgetary_enc_flag := l_value;
1113 end if;
1114
1115 */
1116
1117
1118 -- Get PSA Debug Mode profile value
1119
1120 FND_PROFILE.GET('PSA_DEBUG_MODE', l_value);
1121
1122 IF l_value = 'Y' THEN
1123 -- =========================== FND LOG ===========================
1124 psa_utils.debug_other_string(g_state_level,l_full_path, ' l_value = Y -> g_xla_debug = TRUE');
1125 -- ========================= FND LOG =============================
1126
1127 g_xla_debug := TRUE;
1128 ELSE
1129 -- =========================== FND LOG ===========================
1130 psa_utils.debug_other_string(g_state_level,l_full_path, ' l_value != Y -> g_xla_debug = FALSE');
1131 -- ========================= FND LOG =============================
1132
1133 g_xla_debug := FALSE;
1134 END IF;
1135
1136
1137 -- Get Budgetary Control Option
1138
1139 if ((g_override_flag) and
1140 (p_user_id is not null) and
1141 (p_user_resp_id is not null)) then
1142
1143 FND_PROFILE.GET_SPECIFIC('BUDGETARY_CONTROL_OPTION',
1144 p_user_id,
1145 p_user_resp_id,
1146 g_resp_appl_id,
1147 l_value,
1148 l_defined);
1149 else
1150 FND_PROFILE.GET('BUDGETARY_CONTROL_OPTION', l_value);
1151 end if;
1152
1153 g_bc_option_id := to_number(l_value);
1154
1155 -- =========================== FND LOG ===========================
1156 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_bc_option_id -> ' || g_bc_option_id);
1157 -- ========================= FND LOG =============================
1158
1159 g_return_code := NULL;
1160
1161 g_num_segs := 0;
1162
1163 -- =========================== FND LOG ===========================
1164 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_return_code -> ' || g_return_code);
1165 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_num_segs -> ' || g_num_segs);
1166 -- ========================= FND LOG =============================
1167
1168 for i in 1..30 loop
1169 seg_name(i) := null;
1170 seg_val(i) := null;
1171 end loop;
1172
1173
1174 /*============================+
1175 | Check for PA enabled |
1176 +=============================*/
1177
1178 -- =========================== FND LOG ===========================
1179 psa_utils.debug_other_string(g_state_level,l_full_path, ' Check PA is enable or not ' );
1180 -- ========================= FND LOG =============================
1181
1182 BEGIN
1183 l_industry := NULL;
1184 l_prepare_stmt := NULL;
1185 l_pa_status := 'N';
1186
1187 IF FND_INSTALLATION.GET(275, 275, l_pa_status, l_industry) THEN
1188
1189 IF l_pa_status ='I' THEN
1190
1191 l_pa_enabled := 0;
1192 l_prepare_stmt := 'BEGIN IF PA_BUDGET_FUND_PKG.IS_PA_BC_ENABLED() THEN'||' :1 := 1; END IF; END;';
1193
1194 -- =========================== FND LOG ===========================
1195 psa_utils.debug_other_string(g_state_level,l_full_path, ' l_prepare_stmt -> ' || l_prepare_stmt );
1196 -- ========================= FND LOG =============================
1197
1198 EXECUTE IMMEDIATE l_prepare_stmt USING OUT l_pa_enabled;
1199
1200 -- =========================== FND LOG ===========================
1201 psa_utils.debug_other_string(g_state_level,l_full_path, ' l_pa_enabled -> ' || l_pa_enabled );
1202 -- ========================= FND LOG =============================
1203
1204
1205 IF l_pa_enabled = 1 THEN
1206
1207 g_psa_pacheck := TRUE;
1208
1209 -- =========================== FND LOG ===========================
1210 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_psa_pacheck --> TRUE ' );
1211 -- ========================= FND LOG =============================
1212
1213 END IF;
1214 END IF;
1215 END IF;
1216
1217 EXCEPTION
1218 WHEN OTHERS THEN
1219 g_psa_pacheck := FALSE;
1220
1221 -- =========================== FND LOG ===========================
1222 psa_utils.debug_other_string(g_excep_level,l_full_path, ' g_psa_pacheck --> FALSE ' );
1223 psa_utils.debug_other_string(g_excep_level,l_full_path, ' ERROR: '||sqlerrm );
1224 -- ========================= FND LOG =============================
1225 END;
1226
1227
1228 /*============================+
1229 | Check for GMS enabled |
1230 +=============================*/
1231
1232 -- =========================== FND LOG ===========================
1233 psa_utils.debug_other_string(g_state_level,l_full_path, ' Check GMS is enable or not ' );
1234 -- ========================= FND LOG =============================
1235 BEGIN
1236 l_industry := NULL;
1237 l_prepare_stmt := NULL;
1238 l_gms_status := 'N';
1239
1240 IF FND_INSTALLATION.GET(8402, 8402, l_gms_status, l_industry) THEN
1241
1242 IF l_gms_status ='I' THEN
1243
1244 l_gms_enabled := 0;
1245 l_prepare_stmt := 'BEGIN IF GMS_INSTALL.ENABLED() THEN'||' :1 := 1; END IF; END;';
1246
1247 -- =========================== FND LOG ===========================
1248 psa_utils.debug_other_string(g_state_level,l_full_path, ' l_prepare_stmt -> ' || l_prepare_stmt );
1249 -- ========================= FND LOG =============================
1250
1251 EXECUTE IMMEDIATE l_prepare_stmt USING OUT l_gms_enabled;
1252
1253 -- =========================== FND LOG ===========================
1254 psa_utils.debug_other_string(g_state_level,l_full_path, ' l_gms_enabled -> ' || l_gms_enabled );
1255 -- ========================= FND LOG =============================
1256
1257
1258 IF l_gms_enabled = 1 THEN
1259
1260 g_psa_grantcheck := TRUE;
1261
1262 -- =========================== FND LOG ===========================
1263 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_psa_grantcheck --> TRUE ' );
1264 -- ========================= FND LOG =============================
1265
1266 END IF;
1267 END IF;
1268 END IF;
1269
1270 EXCEPTION
1271 WHEN OTHERS THEN
1272 g_psa_grantcheck := FALSE;
1273
1274 -- =========================== FND LOG ===========================
1275 psa_utils.debug_other_string(g_excep_level,l_full_path, ' g_psa_grantcheck --> FALSE ' );
1276 psa_utils.debug_other_string(g_excep_level,l_full_path, ' ERROR: '||sqlerrm );
1277 -- ========================= FND LOG =============================
1278 END;
1279
1280
1281 /*========================+
1282 | Check CBC Enabled |
1283 +========================*/
1284
1285 -- =========================== FND LOG ===========================
1286 psa_utils.debug_other_string(g_state_level,l_full_path, ' Check CBC is enabled or not' );
1287 -- ========================= FND LOG =============================
1288
1289 BEGIN
1290
1291 IF (l_igi_status = 'I') THEN
1292
1293 l_prepare_stmt := 'SELECT cc_bc_enable_flag FROM igc_cc_bc_enable WHERE set_of_books_id = :1';
1294 -- =========================== FND LOG ===========================
1295 psa_utils.debug_other_string(g_state_level,l_full_path, ' l_prepare_stmt -> ' || l_prepare_stmt );
1296 -- ========================= FND LOG =============================
1297
1298 EXECUTE IMMEDIATE l_prepare_stmt INTO l_cbc_enabled USING g_ledger_id;
1299
1300 IF (l_cbc_enabled = 'Y') THEN
1301 g_cbc_enabled := TRUE;
1302 END IF;
1303 END IF;
1304
1305 EXCEPTION
1306 WHEN OTHERS THEN
1307 g_cbc_enabled := FALSE;
1308 -- =========================== FND LOG ===========================
1309 psa_utils.debug_other_string(g_excep_level,l_full_path, ' g_cbc_enabled --> FALSE ' );
1310 psa_utils.debug_other_string(g_excep_level,l_full_path, ' ERROR: '||sqlerrm );
1311 -- ========================= FND LOG =============================
1312 END;
1313
1314
1315 IF g_cbc_enabled THEN
1316 -- =========================== FND LOG ===========================
1317 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_cbc_enabled --> TRUE');
1318 -- ========================= FND LOG =============================
1319 ELSE
1320 -- =========================== FND LOG ===========================
1321 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_cbc_enabled --> FALSE');
1322 -- ========================= FND LOG =============================
1323 END IF;
1324
1325
1326 /*================================================================================+
1327 | Get Chart of Accounts and Functional Currency Code for this Set of Books |
1328 +================================================================================*/
1329
1330 OPEN set_of_books;
1331 FETCH set_of_books INTO g_coa_id, g_func_curr_code;
1332 CLOSE set_of_books;
1333
1334 -- =========================== FND LOG ===========================
1335 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_coa_id -> ' || g_coa_id);
1336 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_func_curr_code -> ' || g_func_curr_code);
1337 -- ========================= FND LOG =============================
1338
1339 -- ===============================================================
1340 psa_utils.debug_other_string(g_state_level,l_full_path,'Getting value of Profile PSA_ENABLE_EFC');
1341 -- ===============================================================
1342
1343 FND_PROFILE.GET('PSA_ENABLE_EFC',g_enable_efc_flag);
1344
1345 -- ================================================================
1346 psa_utils.debug_other_string(g_state_level,l_full_path,'Value of Profile PSA_ENABLE_EFC' || g_enable_efc_flag);
1347 -- ================================================================
1348
1349 -- =========================== FND LOG ===========================
1350 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN -> TRUE');
1351 -- ========================= FND LOG =============================
1352
1353 return(TRUE);
1354
1355
1356 EXCEPTION
1357
1358 WHEN OTHERS THEN
1359 -- ========================= FND LOG ===========================
1360 psa_utils.debug_other_string(g_excep_level,l_full_path, ' EXCEPTION WHEN OTHERS ' || SQLERRM);
1361 -- ========================= FND LOG ===========================
1362
1363 message_token('PROCEDURE', 'Funds Checker');
1364 message_token('EVENT', SQLERRM);
1365 add_message('SQLGL', 'GL_UNHANDLED_EXCEPTION');
1366
1367 -- ========================= FND LOG ===========================
1368 psa_utils.debug_other_string(g_excep_level,l_full_path, ' RETURN --> FALSE ');
1369 -- ========================= FND LOG ===========================
1370 g_debug := g_debug||' GLXFIN Failed : '||SQLERRM;
1371
1372 return(FALSE);
1373
1374
1375 END glxfin;
1376
1377 /* ============================ GLXFCP =============================== */
1378
1379 -- Funds Check Processor
1380 FUNCTION glxfcp RETURN BOOLEAN IS
1381
1382 PRAGMA AUTONOMOUS_TRANSACTION;
1383
1384 CURSOR source_cat IS
1385 SELECT distinct je_source_name, je_category_name
1386 FROM gl_bc_packets
1387 WHERE packet_id = decode(g_fcmode, 'U', g_packet_id_ursvd, g_packet_id);
1388
1389 l_option_selected NUMBER;
1390
1391 -- ========================= FND LOG ===========================
1392 l_full_path VARCHAR2(100);
1393 -- ========================= FND LOG ===========================
1394 BEGIN
1395
1396 l_full_path := g_path || 'glxfcp';
1397
1398 -- =========================== FND LOG ===========================
1399 psa_utils.debug_other_string(g_state_level,l_full_path, ' GLXFCP - START' );
1400 -- ========================= FND LOG =============================
1401
1402 --
1403 -- If Mode is Unreservation, assign Packet ID to Unreservation Packet ID
1404 -- and initialize Packet ID to 0. This is done here to prevent the approved
1405 -- packet from accidentally being updated to status 'Fatal' in case a fatal
1406 -- error occurs before glxfiu()
1407 --
1408
1409 -- =========================== FND LOG ===========================
1410 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_fcmode -> ' || g_fcmode);
1411 -- ========================= FND LOG =============================
1412
1413 if g_fcmode = 'U' then
1414 g_packet_id_ursvd := g_packet_id;
1415 g_packet_id := 0;
1416 else
1417 g_packet_id_ursvd := 0;
1418 end if;
1419
1420 -- =========================== FND LOG ===========================
1421 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_packet_id_ursvd -> ' || g_packet_id_ursvd);
1422 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_packet_id -> ' || g_packet_id);
1423 -- ========================= FND LOG =============================
1424
1425 IF g_cbc_enabled THEN
1426
1427 -- =========================== FND LOG ===========================
1428 psa_utils.debug_other_string(g_state_level,l_full_path, ' Calling GLZCBC ');
1429 -- ========================= FND LOG =============================
1430
1431 g_cbc_retcode := glzcbc;
1432
1433 -- =========================== FND LOG ===========================
1434 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_cbc_retcode -> ' || g_cbc_retcode);
1435 -- ========================= FND LOG =============================
1436
1437 IF g_cbc_retcode = -1 THEN
1438
1439 -- =========================== FND LOG ===========================
1440 psa_utils.debug_other_string(g_state_level,l_full_path, ' glzcbc RETURN -> FALSE');
1441 psa_utils.debug_other_string(g_state_level,l_full_path, ' ERROR: ROLLBACK, RETURN -> FALSE');
1442 -- ========================= FND LOG =============================
1443
1444 g_debug := g_debug||' GLXFCP Failed : G_CBC_RETOCDE = -1';
1445 -- Bug 3214062
1446 rollback;
1447 RETURN FALSE;
1448
1449 ELSIF g_cbc_retcode = 0 THEN
1450
1451 -- =========================== FND LOG ===========================
1452 psa_utils.debug_other_string(g_state_level,l_full_path, ' Calling glxfrc ');
1453 -- ========================= FND LOG =============================
1454
1455 if not glxfrc then
1456 -- =========================== FND LOG ===========================
1457 psa_utils.debug_other_string(g_state_level,l_full_path, ' glxfrc RETURN -> FALSE');
1458 psa_utils.debug_other_string(g_state_level,l_full_path, ' ERROR: ROLLBACK, RETURN -> FALSE');
1459 -- ========================= FND LOG =============================
1460
1461 -- Bug 3214062
1462 rollback;
1463 RETURN FALSE;
1464 end if;
1465
1466 -- Bug 3214062
1467 commit;
1468
1469 -- =========================== FND LOG ===========================
1470 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN -> TRUE');
1471 -- ========================= FND LOG =============================
1472
1473 RETURN TRUE;
1474
1475 END IF;
1476
1477 END IF; -- g_cbc_enabled
1478
1479 -- =========================== FND LOG ===========================
1480 psa_utils.debug_other_string(g_state_level,l_full_path, ' resetting g_append_je_flag to FALSE ');
1481 -- ========================= FND LOG =============================
1482
1483 -- Reset Append JE Flag
1484 g_append_je_flag := FALSE;
1485
1486
1487 -- If USSGL Option is enabled and Mode is not Unreservation, process
1488 -- USSGL transactions
1489
1490 if ((g_ussgl_option_flag) and
1491 (g_fcmode <> 'U')) then
1492
1493 -- =========================== FND LOG ===========================
1494 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_ussgl_option_flag -> TRUE ');
1495 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_fcmode <> U ');
1496 psa_utils.debug_other_string(g_state_level,l_full_path, ' Calling fv_prepay_pkg ');
1497 -- ========================= FND LOG =============================
1498
1499 if not fv_prepay_pkg then
1500 -- =========================== FND LOG ===========================
1501 psa_utils.debug_other_string(g_state_level,l_full_path, ' fv_prepay_pkg - RETURN -> FALSE');
1502 -- ========================= FND LOG =============================
1503 g_debug := g_debug||' GLXFCP Failed : FV_PREPAY_PKG failed';
1504 rollback;
1505 return (FALSE);
1506 end if;
1507
1508 -- =========================== FND LOG ===========================
1509 psa_utils.debug_other_string(g_state_level,l_full_path, ' Calling glxfug ');
1510 -- ========================= FND LOG =============================
1511
1512 if not glxfug then
1513 -- =========================== FND LOG ===========================
1514 psa_utils.debug_other_string(g_state_level,l_full_path, ' GLXFUG - RETURN -> FALSE');
1515 -- ========================= FND LOG =============================
1516 rollback;
1517 return(FALSE);
1518 end if;
1519
1520 end if;
1521
1522 -- If Project Accounting Funds Check indicated, callout to allow
1523 -- for proper pre-processing.
1524
1525 if g_psa_pacheck then
1526 -- =========================== FND LOG ===========================
1527 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_psa_pacheck -> TRUE');
1528 -- ========================= FND LOG =============================
1529
1530 if not glzpafck then
1531 -- =========================== FND LOG ===========================
1532 psa_utils.debug_other_string(g_state_level,l_full_path, ' glzpafck - RETURN -> FALSE');
1533 -- ========================= FND LOG =============================
1534 rollback;
1535 return(FALSE);
1536 end if;
1537
1538 end if;
1539
1540 -- =========================== FND LOG ===========================
1541 psa_utils.debug_other_string(g_state_level,l_full_path, ' Populating records in PSA_OPTION_DETAILS_GT ');
1542 -- ========================= FND LOG =============================
1543
1544 FOR indx IN source_cat
1545 LOOP
1546 SELECT MIN(CASE) INTO l_option_selected
1547 FROM (
1548 SELECT CASE
1549 WHEN (bc.je_source_name = indx.je_source_name) AND (bc.je_category_name = indx.je_category_name) THEN
1550 1
1551 WHEN (bc.je_source_name = indx.je_source_name) AND (bc.je_category_name = 'Other') THEN
1552 2
1553 WHEN (bc.je_category_name = indx.je_category_name) AND (bc.je_source_name = 'Other') THEN
1554 3
1555 WHEN (bc.je_source_name = 'Other' AND bc.je_category_name = 'Other') THEN
1556 4
1557 END CASE
1558 FROM gl_bc_option_details bc
1559 WHERE bc_option_id = g_bc_option_id);
1560
1561 -- =========================== FND LOG ===========================
1562 psa_utils.debug_other_string(g_state_level,l_full_path, ' l_option_selected -> '||l_option_selected);
1563 -- ========================= FND LOG =============================
1564
1565 INSERT INTO psa_option_details_gt
1566 ( packet_id,
1567 je_source_name,
1568 je_category_name,
1569 gl_bc_option_source,
1570 gl_bc_option_category,
1571 funds_check_level_code,
1572 override_amount,
1573 tolerance_percentage,
1574 tolerance_amount
1575 )
1576 SELECT decode(g_fcmode, 'U', g_packet_id_ursvd, g_packet_id)
1577 ,indx.je_source_name
1578 ,indx.je_category_name
1579 ,decode(l_option_selected,
1580 1, indx.je_source_name,
1581 2, indx.je_source_name,
1582 'Other')
1583 ,decode(l_option_selected,
1584 1, indx.je_category_name,
1585 3, indx.je_category_name,
1586 'Other')
1587 ,funds_check_level_code
1588 ,override_amount
1589 ,tolerance_percentage
1590 ,tolerance_amount
1591 FROM gl_bc_option_details
1592 WHERE bc_option_id = g_bc_option_id
1593 AND je_source_name = decode(l_option_selected,
1594 1, indx.je_source_name,
1595 2, indx.je_source_name,
1596 'Other')
1597 AND je_category_name = decode(l_option_selected,
1598 1, indx.je_category_name,
1599 3, indx.je_category_name,
1600 'Other');
1601
1602 -- =========================== FND LOG ===========================
1603 psa_utils.debug_other_string(g_state_level,l_full_path, sql%rowcount||' Rows Inserted into psa_option_details_gt ');
1604 -- ========================= FND LOG =============================
1605
1606
1607 END LOOP;
1608
1609 -- If Mode is Unreservation, insert Unreservation Packet into the queue
1610 if g_fcmode = 'U' then
1611
1612 -- =========================== FND LOG ===========================
1613 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_fcmode = U ');
1614 -- ========================= FND LOG =============================
1615
1616 if not glxfiu then
1617 -- =========================== FND LOG ===========================
1618 psa_utils.debug_other_string(g_state_level,l_full_path, ' glxfui - RETURN -> FALSE ');
1619 -- ========================= FND LOG =============================
1620 rollback;
1621 return(FALSE);
1622 end if;
1623 end if;
1624
1625 if not glxfss then
1626 -- =========================== FND LOG ===========================
1627 psa_utils.debug_other_string(g_state_level,l_full_path, ' glxfss - RETURN -> FALSE ');
1628 -- ========================= FND LOG =============================
1629 rollback;
1630 return(FALSE);
1631 end if;
1632
1633 if g_overlapping_budget=TRUE then
1634 commit;
1635 return(TRUE);
1636 end if;
1637
1638
1639 -- Check Grants, if extension enabled
1640
1641 gms_retcode := '~';
1642
1643 -- =========================== FND LOG ===========================
1644 psa_utils.debug_other_string(g_state_level,l_full_path, ' gms_retcode -> ' || gms_retcode);
1645 -- ========================= FND LOG =============================
1646
1647 if g_psa_grantcheck then
1648 -- =========================== FND LOG ===========================
1649 psa_utils.debug_other_string(g_state_level,l_full_path, ' Calling glzgchk');
1650 -- ========================= FND LOG =============================
1651 g_psa_grantcheck := glzgchk;
1652 end if;
1653
1654 -- Process Balances
1655
1656 if (g_fcmode <> 'F') then
1657 -- =========================== FND LOG ===========================
1658 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_fcmode <> F');
1659 -- ========================= FND LOG =============================
1660
1661 if not glxfgb then
1662 -- =========================== FND LOG ===========================
1663 psa_utils.debug_other_string(g_state_level,l_full_path, ' glxfgb -> FALSE');
1664 -- ========================= FND LOG =============================
1665 rollback;
1666 return(FALSE);
1667 end if;
1668
1669 end if;
1670
1671 -- ## Update Result Codes
1672 -- ## TROBERTS: Removed Return Code expansion as this applied only
1673 -- ## to the Extended Funds Checker V2 and V3 functionality which
1674 -- ## is not supported in 11.5 and beyond.
1675
1676 if not glxfrc then
1677 -- =========================== FND LOG ===========================
1678 psa_utils.debug_other_string(g_state_level,l_full_path, ' glxfrc -> FALSE');
1679 -- ========================= FND LOG =============================
1680 rollback;
1681 return(FALSE);
1682 end if;
1683
1684 --
1685 -- Need to commit as we exit an autonomous function.
1686 --
1687 commit;
1688
1689 -- =========================== FND LOG ===========================
1690 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN -> TRUE');
1691 -- ========================= FND LOG =============================
1692
1693 return(TRUE);
1694
1695 EXCEPTION
1696
1697 WHEN OTHERS THEN
1698 -- =========================== FND LOG ===========================
1699 psa_utils.debug_other_string(g_excep_level,l_full_path, ' EXCEPTION WHEN OTHERS ' || SQLERRM);
1700 -- ========================= FND LOG =============================
1701
1702 message_token('PROCEDURE', 'Funds Checker');
1703 message_token('EVENT', SQLERRM);
1704 add_message('SQLGL', 'GL_UNHANDLED_EXCEPTION');
1705
1706 g_debug := g_debug||' GLXFCP Failed : '||SQLERRM;
1707 -- Bug 3214062
1708 rollback;
1709
1710 -- =========================== FND LOG ===========================
1711 psa_utils.debug_other_string(g_excep_level,l_full_path, ' RETURN -> TRUE');
1712 -- ========================= FND LOG =============================
1713 return(FALSE);
1714
1715 END glxfcp;
1716
1717 /* ============================== GLXFUG ================================ */
1718
1719 -- Process USSGL Transactions
1720
1721 -- This Module inserts Budgetary or Proprietary actual transactions into
1722 -- the queue table as needed and creates new Budgetary or Proprietary Code
1723 -- Combinations if they do not already exist in the Code Combinations table
1724
1725 FUNCTION glxfug RETURN BOOLEAN IS
1726
1727 l_tmpmsg VARCHAR2(70);
1728 l_rowid VARCHAR2(100);
1729 l_ccid_out NUMBER;
1730 l_ccid NUMBER;
1731
1732 -- Maximum Length for this SQL Statement is 3708
1733
1734 sql_ussgl VARCHAR2(7000);
1735 cur_ussgl INTEGER;
1736 num_ussgl INTEGER;
1737 ignore INTEGER;
1738
1739 segment1 gl_code_combinations.segment1%TYPE;
1740 segment2 gl_code_combinations.segment2%TYPE;
1741 segment3 gl_code_combinations.segment3%TYPE;
1742 segment4 gl_code_combinations.segment4%TYPE;
1743 segment5 gl_code_combinations.segment5%TYPE;
1744 segment6 gl_code_combinations.segment6%TYPE;
1745 segment7 gl_code_combinations.segment7%TYPE;
1746 segment8 gl_code_combinations.segment8%TYPE;
1747 segment9 gl_code_combinations.segment9%TYPE;
1748 segment10 gl_code_combinations.segment10%TYPE;
1749 segment11 gl_code_combinations.segment11%TYPE;
1750 segment12 gl_code_combinations.segment12%TYPE;
1751 segment13 gl_code_combinations.segment13%TYPE;
1752 segment14 gl_code_combinations.segment14%TYPE;
1753 segment15 gl_code_combinations.segment15%TYPE;
1754 segment16 gl_code_combinations.segment16%TYPE;
1755 segment17 gl_code_combinations.segment17%TYPE;
1756 segment18 gl_code_combinations.segment18%TYPE;
1757 segment19 gl_code_combinations.segment19%TYPE;
1758 segment20 gl_code_combinations.segment20%TYPE;
1759 segment21 gl_code_combinations.segment21%TYPE;
1760 segment22 gl_code_combinations.segment22%TYPE;
1761 segment23 gl_code_combinations.segment23%TYPE;
1762 segment24 gl_code_combinations.segment24%TYPE;
1763 segment25 gl_code_combinations.segment25%TYPE;
1764 segment26 gl_code_combinations.segment26%TYPE;
1765 segment27 gl_code_combinations.segment27%TYPE;
1766 segment28 gl_code_combinations.segment28%TYPE;
1767 segment29 gl_code_combinations.segment29%TYPE;
1768 segment30 gl_code_combinations.segment30%TYPE;
1769
1770 cursor ussgl is
1771 select 'USSGL Rows need to be created'
1772 from dual
1773 where exists
1774 (
1775 select 'Transaction with USSGL Code'
1776 from gl_bc_packets bp
1777 where bp.packet_id = g_packet_id
1778 and bp.ussgl_transaction_code is not null
1779 );
1780
1781 cursor append_je is
1782 select 'Associated Generated JEs to be appended or inserted'
1783 from dual
1784 where exists
1785 (
1786 select 'Associated Generated Row from existing GL Batch'
1787 from gl_bc_packets bp
1788 where bp.packet_id = g_packet_id
1789 and bp.je_batch_id is not null
1790 and bp.je_batch_id >= 0
1791 and bp.ussgl_transaction_code is not null
1792 );
1793
1794 -- ========================= FND LOG ===========================
1795 l_full_path VARCHAR2(100);
1796 -- ========================= FND LOG ===========================
1797 BEGIN
1798
1799 l_full_path := g_path || 'glxfug';
1800
1801 -- =========================== FND LOG ===========================
1802 psa_utils.debug_other_string(g_state_level,l_full_path, ' GLXFUG - START' );
1803 -- ========================= FND LOG =============================
1804
1805 -- Check that USSGL transactions need to be created since the overhead for
1806 -- constructing and executing the Dynamic SQL for inserting USSGL
1807 -- Transactions is much higher than this check
1808
1809 open ussgl;
1810
1811 fetch ussgl into l_tmpmsg;
1812
1813 -- =========================== FND LOG ===========================
1814 psa_utils.debug_other_string(g_state_level,l_full_path, ' l_tmpmsg -> ' || l_tmpmsg );
1815 -- ========================= FND LOG =============================
1816
1817 -- No USSGL Transactions need to be created
1818 if ussgl%NOTFOUND then
1819 -- =========================== FND LOG ===========================
1820 psa_utils.debug_other_string(g_state_level,l_full_path, ' goto normal_exit label' );
1821 -- ========================= FND LOG =============================
1822 goto normal_exit;
1823 end if;
1824
1825 close ussgl;
1826
1827 -- Check if there are associated generated Journal Entry lines
1828 -- to be appended to an existing Actual Batch or if a separate
1829 -- Actual Batch would need to be created if the Originating
1830 -- source is an existing Encumbrance Batch
1831
1832 open append_je;
1833 fetch append_je into l_tmpmsg;
1834
1835 if append_je%FOUND then
1836 -- =========================== FND LOG ===========================
1837 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_append_je_flag -> TRUE');
1838 -- ========================= FND LOG =============================
1839 g_append_je_flag := TRUE;
1840 else
1841 -- =========================== FND LOG ===========================
1842 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_append_je_flag -> FALSE');
1843 -- ========================= FND LOG =============================
1844 g_append_je_flag := FALSE;
1845 end if;
1846
1847 close append_je;
1848
1849
1850 UPDATE GL_BC_PACKETS BP
1851 SET BP.ussgl_parent_id = GL_USSGL_PARENT_S.NEXTVAL
1852 WHERE
1853 BP.packet_id = g_packet_id
1854 AND BP.ussgl_transaction_code IS NOT NULL;
1855
1856 -- =========================== FND LOG ===========================
1857 psa_utils.debug_other_string(g_state_level,l_full_path, ' Update gl_bc_packets -> ' || SQL%ROWCOUNT );
1858 -- ========================= FND LOG =============================
1859
1860 if g_append_je_flag then
1861
1862 -- ## ----------------------------------------------------------+
1863 -- ## Bug: 1387967/2178715 Federal AR |
1864 -- ## Drill down of USSGL generated transactions to AR. |
1865 -- ## ----------------------------------------------------------+
1866
1867 UPDATE GL_BC_PACKETS BP
1868 SET
1869 ( BP.reference1,
1870 BP.reference2,
1871 BP.reference3,
1872 BP.reference4,
1873 BP.reference5,
1874 BP.reference6,
1875 BP.reference7,
1876 BP.reference8,
1877 BP.reference9,
1878 BP.reference10) =
1879 (SELECT GI.reference_1,
1880 GI.reference_2,
1881 GI.reference_3,
1882 GI.reference_4,
1883 GI.reference_5,
1884 GI.reference_6,
1885 GI.reference_7,
1886 GI.reference_8,
1887 GI.reference_9,
1888 GI.reference_10
1889 FROM gl_import_references GI
1890 WHERE GI.je_line_num = BP.je_line_num
1891 AND GI.je_header_id= BP.je_header_id
1892 AND GI.je_batch_id = BP.je_batch_id)
1893 WHERE
1894 BP.packet_id = g_packet_id
1895 AND BP.ussgl_transaction_code IS NOT NULL;
1896
1897 end if;
1898
1899 -- =========================== FND LOG ===========================
1900 psa_utils.debug_other_string(g_state_level,l_full_path, ' Update gl_bc_packets -> ' || SQL%ROWCOUNT );
1901 psa_utils.debug_other_string(g_state_level,l_full_path, 'Calling glxfkf' );
1902 -- ========================= FND LOG =============================
1903
1904 -- Retrieve Flex Info for the Flex Structure
1905 if not glxfkf then
1906 -- =========================== FND LOG ===========================
1907 psa_utils.debug_other_string(g_state_level,l_full_path, ' glxfkf ->False --> RETURN FALSE' );
1908 -- ========================= FND LOG =============================
1909 return(FALSE);
1910 end if;
1911
1912
1913 -- Insertion of USSGL transactions into gl_bc_packets
1914
1915 -- When the USSGL Option is set, this process is executed prior to setting
1916 -- up of the denormalized columns and this applies to Funds Check and
1917 -- Funds Reservation. For all packet transactions with a USSGL transaction
1918 -- code, this function creates all the required budgetary or proprietary
1919 -- actual transaction records depending on the USSGL transaction codes and
1920 -- the associated Debit and Credit Account Segment values pair defined in
1921 -- gl_ussgl_account_pairs
1922
1923 -- The number of additional transactions generated for each originating
1924 -- transaction equals the number of Debit and Credit Account Segment
1925 -- values associated with the originating USSGL transaction code. For
1926 -- example, if there are 3 Proprietary transactions with non-null USSGL
1927 -- transaction codes in the packet, and for each of the codes, 2 Debit and
1928 -- Credit Account Pairs have been defined, then the number of additional
1929 -- transactions generated will be 12 (3 transactions * 2 acct pairs/code *
1930 -- 2 acct/pair). No Consolidation is done for multiple generated
1931 -- generated transactions with the same account
1932
1933 -- The Entered and Accounted amount columns for the generated transactions
1934 -- are filled up as follows :
1935 --
1936 -- Originating Generated Generated
1937 -- Transaction Debit Transaction Credit Transaction
1938 -- Account Type DR CR DR CR
1939 -- ------------ ----------------- ------------------
1940 -- 'A', 'E', 'D' O_DR O_CR O_CR O_DR
1941 --
1942 -- 'L', 'O', 'R', 'C' O_CR O_DR O_DR O_CR
1943 --
1944 -- O_DR : Entered/Accounted Debit Amount for Originating Transaction
1945 -- O_CR : Entered/Accounted Credit Amount for Originating Transaction
1946
1947 -- Bug 3111554:
1948 -- If profile GL_REVERSE_TC_OPTION = 'N' then entered and accounted
1949 -- amounts are derived as follows.
1950
1951 -- decode(nvl(PET.event_type, 'X'),
1952 -- lu.lookup_code, BP.entered_dr,
1953 -- 'X', decode(CCO.account_type || LU.lookup_code,
1954 -- 'AD', BP.entered_dr,
1955 -- 'ED', BP.entered_dr,
1956 -- 'DD', BP.entered_dr,
1957 -- 'LC', BP.entered_dr,
1958 -- 'OC', BP.entered_dr,
1959 -- 'RC', BP.entered_dr,
1960 -- 'CC', BP.entered_dr,
1961 -- BP.entered_cr),
1962 -- BP.entered_cr),
1963 -- decode(nvl(PET.event_type, 'X'),
1964 -- lu.lookup_code, BP.entered_cr,
1965 -- 'X', decode(CCO.account_type LU.lookup_code,
1966 -- 'AD', BP.entered_cr,
1967 -- 'ED', BP.entered_cr,
1968 -- 'DD', BP.entered_cr,
1969 -- 'LC', BP.entered_cr,
1970 -- 'OC', BP.entered_cr,
1971 -- 'RC', BP.entered_cr,
1972 -- 'CC', BP.entered_cr,
1973 -- BP.entered_dr),
1974 -- BP.entered_dr)
1975
1976 -- When the Code Combination for a generated transaction does not exist,
1977 -- the transaction is created and the CCID is initialized to the negative
1978 -- value of the originating transaction's CCID. These transactions are
1979 -- then inserted into the Code Combinations table with new CCIDs
1980
1981 sql_ussgl := 'insert into gl_bc_packets (packet_id, ' ||
1982 'ledger_id, ' ||
1983 'je_source_name, ' ||
1984 'je_category_name, ' ||
1985 'code_combination_id, ' ||
1986 'actual_flag, ' ||
1987 'period_name, ' ||
1988 'period_year, ' ||
1989 'period_num, ' ||
1990 'quarter_num, ' ||
1991 'currency_code, ' ||
1992 'status_code, ' ||
1993 'last_update_date, ' ||
1994 'last_updated_by, ' ||
1995 'entered_dr, ' ||
1996 'entered_cr, ' ||
1997 'accounted_dr, ' ||
1998 'accounted_cr, ' ||
1999 'originating_rowid, ' ||
2000 'account_segment_value, ' ||
2001 'je_batch_name, ' ||
2002 'je_batch_id, ' ||
2003 'je_header_id, ' ||
2004 'je_line_num, '||
2005 'reference1, ' ||
2006 'reference2, ' ||
2007 'reference3, ' ||
2008 'reference4, ' ||
2009 'reference5, ' ||
2010 'reference6, ' ||
2011 'reference7, ' ||
2012 'reference8, ' ||
2013 'reference9, ' ||
2014 'reference10, '||
2015 'ussgl_link_to_parent_id, '||
2016 'session_id, '||
2017 'serial_id, ' ||
2018 'application_id) ';
2019
2020 sql_ussgl := sql_ussgl ||
2021 'select bp.packet_id, ' ||
2022 'bp.ledger_id, ' ||
2023 'bp.je_source_name, ' ||
2024 'bp.je_category_name, ' ||
2025 'decode(ccg.code_combination_id, ' ||
2026 'cco.code_combination_id, ' ||
2027 '-1 * cco.code_combination_id, ' ||
2028 'ccg.code_combination_id), ' ||
2029 '''A'', ' ||
2030 'bp.period_name, ' ||
2031 'bp.period_year, ' ||
2032 'bp.period_num, ' ||
2033 'bp.quarter_num, ' ||
2034 'bp.currency_code, ' ||
2035 'bp.status_code, ' ||
2036 'bp.last_update_date, ' ||
2037 'bp.last_updated_by, ';
2038
2039 -- =========================== FND LOG ===========================
2040 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_reverse_tc_flag -> ' || g_reverse_tc_flag );
2041 -- ========================= FND LOG =============================
2042
2043 if g_reverse_tc_flag = 'N' then
2044
2045 sql_ussgl := sql_ussgl ||
2046 'decode(nvl(PET.event_type, ''X''), ' ||
2047 'lu.lookup_code, BP.entered_dr,' ||
2048 '''X'', decode(CCO.account_type || LU.lookup_code,' ||
2049 '''AD'', BP.entered_dr, ' ||
2050 '''ED'', BP.entered_dr, ' ||
2051 '''DD'', BP.entered_dr, ' ||
2052 '''LC'', BP.entered_dr, ' ||
2053 '''OC'', BP.entered_dr, ' ||
2054 '''RC'', BP.entered_dr, ' ||
2055 '''CC'', BP.entered_dr, BP.entered_cr), ' ||
2056 'BP.entered_cr),' ||
2057 'decode(nvl(PET.event_type, ''X''), ' ||
2058 'lu.lookup_code, BP.entered_cr,' ||
2059 '''X'', decode(CCO.account_type || LU.lookup_code,' ||
2060 '''AD'', BP.entered_cr, ' ||
2061 '''ED'', BP.entered_cr, ' ||
2062 '''DD'', BP.entered_cr, ' ||
2063 '''LC'', BP.entered_cr, ' ||
2064 '''OC'', BP.entered_cr, ' ||
2065 '''RC'', BP.entered_cr, ' ||
2066 '''CC'', BP.entered_cr, BP.entered_dr),' ||
2067 'BP.entered_dr),' ||
2068 'decode(nvl(PET.event_type, ''X''),' ||
2069 'lu.lookup_code, BP.accounted_dr,' ||
2070 '''X'', decode(CCO.account_type || LU.lookup_code,' ||
2071 '''AD'', BP.accounted_dr, ' ||
2072 '''ED'', BP.accounted_dr, ' ||
2073 '''DD'', BP.accounted_dr, ' ||
2074 '''LC'', BP.accounted_dr, ' ||
2075 '''OC'', BP.accounted_dr, ' ||
2076 '''RC'', BP.accounted_dr, ' ||
2077 '''CC'', BP.accounted_dr, BP.accounted_cr),' ||
2078 'BP.accounted_cr),' ||
2079 'decode(nvl(PET.event_type, ''X''),' ||
2080 'lu.lookup_code, BP.accounted_cr,' ||
2081 '''X'', decode(CCO.account_type || LU.lookup_code,' ||
2082 '''AD'', BP.accounted_cr, ' ||
2083 '''ED'', BP.accounted_cr, ' ||
2084 '''DD'', BP.accounted_cr, ' ||
2085 '''LC'', BP.accounted_cr, ' ||
2086 '''OC'', BP.accounted_cr, ' ||
2087 '''RC'', BP.accounted_cr, ' ||
2088 '''CC'', BP.accounted_cr, BP.accounted_dr),' ||
2089 'BP.accounted_dr), ';
2090 else
2091
2092
2093 sql_ussgl := sql_ussgl ||
2094 'decode(cco.account_type || lu.lookup_code, ' ||
2095 '''AD'', bp.entered_dr, ' ||
2096 '''ED'', bp.entered_dr, ' ||
2097 '''DD'', bp.entered_dr, ' ||
2098 '''LC'', bp.entered_dr, ' ||
2099 '''OC'', bp.entered_dr, ' ||
2100 '''RC'', bp.entered_dr, ' ||
2101 '''CC'', bp.entered_dr, bp.entered_cr), ' ||
2102 'decode(cco.account_type || lu.lookup_code, ' ||
2103 '''AD'', bp.entered_cr, ' ||
2104 '''ED'', bp.entered_cr, ' ||
2105 '''DD'', bp.entered_cr, ' ||
2106 '''LC'', bp.entered_cr, ' ||
2107 '''OC'', bp.entered_cr, ' ||
2108 '''RC'', bp.entered_cr, ' ||
2109 '''CC'', bp.entered_cr, bp.entered_dr), ' ||
2110 'decode(cco.account_type || lu.lookup_code, ' ||
2111 '''AD'', bp.accounted_dr, ' ||
2112 '''ED'', bp.accounted_dr, ' ||
2113 '''DD'', bp.accounted_dr, ' ||
2114 '''LC'', bp.accounted_dr, ' ||
2115 '''OC'', bp.accounted_dr, ' ||
2116 '''RC'', bp.accounted_dr, ' ||
2117 '''CC'', bp.accounted_dr, bp.accounted_cr), ' ||
2118 'decode(cco.account_type || lu.lookup_code, ' ||
2119 '''AD'', bp.accounted_cr, ' ||
2120 '''ED'', bp.accounted_cr, ' ||
2121 '''DD'', bp.accounted_cr, ' ||
2122 '''LC'', bp.accounted_cr, ' ||
2123 '''OC'', bp.accounted_cr, ' ||
2124 '''RC'', bp.accounted_cr, ' ||
2125 '''CC'', bp.accounted_cr, bp.accounted_dr), ';
2126 end if;
2127
2128 sql_ussgl := sql_ussgl ||
2129 'bp.rowid, ' ||
2130 'decode(ccg.code_combination_id, ' ||
2131 'cco.code_combination_id, ' ||
2132 'decode(lu.lookup_code, ' ||
2133 '''D'', guap.dr_account_segment_value, ' ||
2134 '''C'', guap.cr_account_segment_value), ' ||
2135 'ccg.' || seg_name(g_acct_seg_index) || '), ' ||
2136 'bp.je_batch_name, ' ||
2137 'bp.je_batch_id, ' ||
2138 'bp.je_header_id, ' ||
2139 'bp.je_line_num, '||
2140 'bp.reference1, ' ||
2141 'bp.reference2, ' ||
2142 'bp.reference3, ' ||
2143 'bp.reference4, ' ||
2144 'bp.reference5, ' ||
2145 'bp.reference6, ' ||
2146 'bp.reference7, ' ||
2147 'bp.reference8, ' ||
2148 'bp.reference9, ' ||
2149 'bp.reference10, '||
2150 'bp.ussgl_parent_id, '||
2151 g_session_id||','||
2152 g_serial_id||','||
2153 g_resp_appl_id ;
2154
2155 if g_reverse_tc_flag = 'N' then
2156
2157 sql_ussgl := sql_ussgl ||
2158 ' from gl_lookups lu, ' ||
2159 'gl_ussgl_transaction_codes uc, ' ||
2160 'gl_ussgl_account_pairs guap, ' ||
2161 'gl_code_combinations ccg, ' ||
2162 'gl_code_combinations cco, ' ||
2163 'gl_bc_packets bp, ' ||
2164 'psa_event_types pet ' ||
2165 'where lu.lookup_type = ''DR_CR'' ' ||
2166 'and pet.je_source (+) = bp.je_source_name ' ||
2167 -- modified for bug 4167009
2168 'and pet.je_category (+) = ' ||
2169 ' decode(bp.je_category_name, '|| '''Payments'','||
2170 'decode(substr(bp.reference5, instr(bp.reference5,' ||'''-'', -1,1)+1, 3),'||
2171 '''INT'' ,'|| '''Purchase Invoices'','||
2172 'bp.je_category_name), bp.je_category_name )' ||
2173 'and uc.chart_of_accounts_id = ' ||
2174 'guap.chart_of_accounts_id ' ||
2175 'and uc.ussgl_transaction_code = ' ||
2176 'bp.ussgl_transaction_code ' ||
2177 'and sysdate between ' ||
2178 'nvl(uc.start_date_active, sysdate) ' ||
2179 'and nvl(uc.end_date_active, sysdate) ' ||
2180 'and guap.chart_of_accounts_id = ' || g_coa_id || ' ' ||
2181 'and guap.ussgl_transaction_code = ' ||
2182 'bp.ussgl_transaction_code ' ||
2183 'and ccg.code_combination_id = ' ||
2184 '(' ||
2185 'select nvl(min(ccg1.code_combination_id), ' ||
2186 'cco.code_combination_id) ' ||
2187 'from gl_code_combinations ccg1 ' ||
2188 'where ccg1.chart_of_accounts_id = ' ||
2189 g_coa_id;
2190 else
2191
2192 sql_ussgl := sql_ussgl ||
2193
2194 ' from gl_lookups lu, ' ||
2195 'gl_ussgl_transaction_codes uc, ' ||
2196 'gl_ussgl_account_pairs guap, ' ||
2197 'gl_code_combinations ccg, ' ||
2198 'gl_code_combinations cco, ' ||
2199 'gl_bc_packets bp ' ||
2200 'where lu.lookup_type = ''DR_CR'' ' ||
2201 'and uc.chart_of_accounts_id = ' ||
2202 'guap.chart_of_accounts_id ' ||
2203 'and uc.ussgl_transaction_code = ' ||
2204 'bp.ussgl_transaction_code ' ||
2205 'and sysdate between ' ||
2206 'nvl(uc.start_date_active, sysdate) ' ||
2207 'and nvl(uc.end_date_active, sysdate) ' ||
2208 'and guap.chart_of_accounts_id = ' || g_coa_id || ' ' ||
2209 'and guap.ussgl_transaction_code = ' ||
2210 'bp.ussgl_transaction_code ' ||
2211 'and ccg.code_combination_id = ' ||
2212 '(' ||
2213 'select nvl(min(ccg1.code_combination_id), ' ||
2214 'cco.code_combination_id) ' ||
2215 'from gl_code_combinations ccg1 ' ||
2216 'where ccg1.chart_of_accounts_id = ' ||
2217 g_coa_id;
2218 end if;
2219
2220
2221 for i in 1..g_num_segs loop
2222
2223 if seg_name(i) is not null then
2224
2225 if (i <> g_acct_seg_index) then
2226 sql_ussgl := sql_ussgl ||
2227 ' and ccg1.' || seg_name(i) || ' = ' ||
2228 'cco.' || seg_name(i);
2229 else
2230 sql_ussgl := sql_ussgl ||
2231 ' and ccg1.' || seg_name(i) || ' = ' ||
2232 'decode(lu.lookup_code, ' ||
2233 '''D'', guap.dr_account_segment_value, ' ||
2234 '''C'', guap.cr_account_segment_value)';
2235 end if;
2236
2237 end if;
2238
2239 end loop;
2240
2241 sql_ussgl := sql_ussgl ||
2242 ') ' ||
2243 'and cco.code_combination_id = bp.code_combination_id ' ||
2244 'and bp.packet_id = ' || g_packet_id || ' ' ||
2245 'and bp.ussgl_transaction_code is not null';
2246
2247 -- =========================== FND LOG ===========================
2248 psa_utils.debug_other_string(g_state_level,l_full_path, ' sql_ussgl -> ' || SUBSTR(sql_ussgl,1,3500));
2249 psa_utils.debug_other_string(g_state_level,l_full_path, ' sql_ussgl -> ' || SUBSTR(sql_ussgl,3500,7000));
2250 -- ========================= FND LOG =============================
2251
2252 execute immediate sql_ussgl;
2253
2254 -- =========================== FND LOG ===========================
2255 psa_utils.debug_other_string(g_state_level,l_full_path, 'USSGL Rows Inserted: '||sql%rowcount);
2256 -- ========================= FND LOG =============================
2257
2258 -- Now that the USSGL Transactions have been generated in the queue, we
2259 -- pick up the Code Combinations which need to be created in the Code
2260 -- Combinations table
2261
2262 sql_ussgl := 'select DISTINCT ';
2263
2264 -- Call Flex API for inserting a new combination of Segment Values
2265
2266 for i in 1..g_num_segs loop
2267
2268 if (i <> g_acct_seg_index) then
2269 sql_ussgl := sql_ussgl ||
2270 seg_name(i) || ', ';
2271 else
2272 sql_ussgl := sql_ussgl ||
2273 'bp.account_segment_value, ';
2274 end if;
2275
2276 end loop;
2277
2278 sql_ussgl := sql_ussgl ||
2279 'bp.code_combination_id ' ||
2280 'from gl_code_combinations cc, ' ||
2281 'gl_bc_packets bp ' ||
2282 'where cc.code_combination_id = -1 * bp.code_combination_id ' ||
2283 'and bp.packet_id = ' || g_packet_id || ' ' ||
2284 'and bp.code_combination_id < 0 ' ||
2285 'and bp.account_segment_value is not null';
2286
2287 -- =========================== FND LOG ===========================
2288 psa_utils.debug_other_string(g_state_level,l_full_path, ' sql_ussgl1 -> ' || SUBSTR(sql_ussgl,1,3500));
2289 psa_utils.debug_other_string(g_state_level,l_full_path, ' sql_ussgl1 -> ' || SUBSTR(sql_ussgl,3500,7000));
2290 -- ========================= FND LOG =============================
2291
2292 cur_ussgl := dbms_sql.open_cursor;
2293 dbms_sql.parse(cur_ussgl, sql_ussgl, dbms_sql.v7);
2294
2295 for i in 1..g_num_segs loop
2296 dbms_sql.define_column(cur_ussgl, i, 'segment' || i, 30);
2297 end loop;
2298
2299 dbms_sql.define_column(cur_ussgl, g_num_segs + 1, l_ccid);
2300
2301 ignore := dbms_sql.execute(cur_ussgl);
2302
2303 loop
2304
2305 if dbms_sql.fetch_rows(cur_ussgl) > 0 then
2306
2307 for i in 1..g_num_segs loop
2308 dbms_sql.column_value(cur_ussgl, i, seg_val(i));
2309 end loop;
2310
2311 dbms_sql.column_value(cur_ussgl, g_num_segs + 1, l_ccid);
2312
2313 if not FND_FLEX_EXT.GET_COMBINATION_ID('SQLGL', 'GL#', g_coa_id,
2314 sysdate, g_num_segs, seg_val, l_ccid_out) then
2315 goto return_invalid;
2316 end if;
2317
2318
2319 -- Commit to allow other Users to create similar combinations on any
2320 -- flexfield
2321
2322 commit;
2323
2324
2325 -- Update the CCID of the USSGL transaction in the Packet
2326
2327 update gl_bc_packets bp
2328 set bp.code_combination_id = l_ccid_out
2329 where bp.code_combination_id = l_ccid
2330 and bp.account_segment_value=seg_val(g_acct_seg_index);
2331
2332 -- =========================== FND LOG ===========================
2333 psa_utils.debug_other_string(g_state_level,l_full_path, ' update gl_bc_packets -> ' || SQL%ROWCOUNT);
2334 -- ========================= FND LOG =============================
2335
2336 else
2337 exit;
2338 end if;
2339
2340 end loop;
2341
2342 dbms_sql.close_cursor(cur_ussgl);
2343
2344 -- =========================== FND LOG ===========================
2345 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_fcmode -> ' || g_fcmode);
2346 -- ========================= FND LOG =============================
2347
2348 -- Exit Function if Mode is Check
2349 if g_fcmode = 'C' then
2350 -- =========================== FND LOG ===========================
2351 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_fcmode = C -> goto normal_exit label');
2352 -- ========================= FND LOG =============================
2353 goto normal_exit;
2354 end if;
2355
2356 -- =========================== FND LOG ===========================
2357 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_fcmode != C -> RETURN TRUE');
2358 -- ========================= FND LOG =============================
2359
2360 return(TRUE);
2361
2362 <<normal_exit>>
2363
2364 -- =========================== FND LOG ===========================
2365 psa_utils.debug_other_string(g_state_level,l_full_path, ' reached normal_exit label ');
2366 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN -> TRUE ');
2367 -- ========================= FND LOG =============================
2368
2369 if ussgl%ISOPEN then
2370 close ussgl;
2371 end if;
2372
2373 return(TRUE);
2374
2375 <<return_invalid>>
2376
2377 -- =========================== FND LOG ===========================
2378 psa_utils.debug_other_string(g_state_level,l_full_path, ' reached return_invalid label ');
2379 -- ========================= FND LOG =============================
2380
2381 if dbms_sql.is_open(cur_ussgl) then
2382 dbms_sql.close_cursor(cur_ussgl);
2383 end if;
2384
2385 message_token('PROCEDURE', 'Funds Checker');
2386 message_token('EVENT', FND_MESSAGE.GET_ENCODED);
2387 add_message('SQLGL', 'GL_UNHANDLED_EXCEPTION');
2388
2389 -- =========================== FND LOG ===========================
2390 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN -> FALSE ');
2391 -- ========================= FND LOG =============================
2392
2393 g_debug := g_debug||' GLXFUG Failed : FND_FLEX_EXT.GET_COMBINATION_ID returned FALSE';
2394
2395 return(FALSE);
2396
2397
2398 EXCEPTION
2399
2400 WHEN OTHERS THEN
2401
2402 -- =========================== FND LOG ===========================
2403 psa_utils.debug_other_string(g_excep_level,l_full_path, ' WHEN OTHERS EXCEPTION ' || SQLERRM);
2404 -- ========================= FND LOG =============================
2405
2406 if ussgl%ISOPEN then
2407 close ussgl;
2408 end if;
2409
2410 if dbms_sql.is_open(cur_ussgl) then
2411 dbms_sql.close_cursor(cur_ussgl);
2412 end if;
2413
2414 if append_je%ISOPEN then
2415 close append_je;
2416 end if;
2417
2418 message_token('PROCEDURE', 'Funds Checker');
2419 message_token('EVENT', SQLERRM);
2420 add_message('SQLGL', 'GL_UNHANDLED_EXCEPTION');
2421
2422 -- =========================== FND LOG ===========================
2423 psa_utils.debug_other_string(g_excep_level,l_full_path, ' RETURN -> FALSE ');
2424 -- ========================= FND LOG =============================
2425
2426 g_debug := g_debug||' GLXFUG Failed : '||SQLERRM;
2427 return(FALSE);
2428
2429 END glxfug;
2430
2431 /* =========================== GLXFKF ========================= */
2432
2433 -- Retrieve Flex Info for the Flex Structure
2434 -- This Function retrieves Flex Info such as Active Segment Info and the
2435 -- Accounting Segment Index
2436
2437 FUNCTION glxfkf RETURN BOOLEAN IS
2438
2439 others EXCEPTION;
2440
2441 cursor seginfo(appl_id NUMBER,
2442 flex_code VARCHAR2,
2443 flex_num NUMBER) is
2444 select application_column_name
2445 from fnd_id_flex_segments
2446 where application_id = appl_id
2447 and id_flex_code = flex_code
2448 and id_flex_num = flex_num
2449 and enabled_flag = 'Y'
2450 order by segment_num;
2451
2452 -- ========================= FND LOG ===========================
2453 l_full_path VARCHAR2(100);
2454 -- ========================= FND LOG ===========================
2455 BEGIN
2456
2457 l_full_path := g_path || 'glxfkf';
2458
2459 -- =========================== FND LOG ===========================
2460 psa_utils.debug_other_string(g_state_level,l_full_path, ' GLXFUF - START' );
2461 -- ========================= FND LOG =============================
2462
2463 -- Retrieve Active Segment Info
2464 for c_seginfo in seginfo(101, 'GL#', g_coa_id) loop
2465 g_num_segs := g_num_segs + 1;
2466 seg_name(g_num_segs) := c_seginfo.application_column_name;
2467 end loop;
2468
2469 -- Get Cardinal Order or Index Number of the Account Segment
2470 if not FND_FLEX_APIS.GET_QUALIFIER_SEGNUM(101,
2471 'GL#',
2472 g_coa_id,
2473 'GL_ACCOUNT',
2474 g_acct_seg_index) then
2475 message_token('ROUTINE', 'GL_FC_PKG');
2476 add_message('FND', 'FLEXGL-NO ACCT SEG');
2477 -- =========================== FND LOG ===========================
2478 psa_utils.debug_other_string(g_state_level,l_full_path, ' RAISE OTHERS ' );
2479 -- ========================= FND LOG =============================
2480 g_debug := g_debug||' GLXFKF Failed : FND_FLEX_APIS.GET_QUALIFIER_SEGNUM returned FALSE';
2481 raise others;
2482 end if;
2483
2484 -- =========================== FND LOG ===========================
2485 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_acct_seg_index -> ' || g_acct_seg_index );
2486 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN -> TRUE ');
2487 -- ========================= FND LOG =============================
2488
2489 return(TRUE);
2490
2491
2492 EXCEPTION
2493
2494 WHEN OTHERS THEN
2495 -- =========================== FND LOG ===========================
2496 psa_utils.debug_other_string(g_excep_level,l_full_path, ' EXCEPTION WHEN OTHERS' || SQLERRM );
2497 -- ========================= FND LOG =============================
2498
2499 message_token('PROCEDURE', 'Funds Checker');
2500 message_token('EVENT', SQLERRM);
2501 add_message('SQLGL', 'GL_UNHANDLED_EXCEPTION');
2502
2503 -- =========================== FND LOG ===========================
2504 psa_utils.debug_other_string(g_excep_level,l_full_path, ' RETURN -> FALSE' );
2505 -- ========================= FND LOG =============================
2506
2507 g_debug := g_debug||' GLXFKF Failed : '||SQLERRM;
2508 return(FALSE);
2509
2510 END glxfkf;
2511
2512 /* =========================== GLXFIU =============================== */
2513
2514 -- Insert Unreservation Packet into the Queue
2515
2516 -- All transactions including associated generated transactions are created
2517 -- out of the packet being unreserved by copying over most of the column
2518 -- values with the exception of the amount and denormalized column values.
2519 -- For the Amount columns, the Debit and Credit values are swapped to create
2520 -- a reversal effect while the denormalized columns like Tolerance and
2521 -- Override info are retrieved from the existing system settings. This is to
2522 -- facilitate cases where there is a need to overcome a Funds Reservation
2523 -- failure by modifying the Tolerance/Override Settings in the Budgetary
2524 -- Control Options. The tie-back mechanism for the originating and associated
2525 -- generated transactions, originating_rowid in the generated lines, are also
2526 -- preserved in the unreservation packet through a separate update SQL
2527
2528 -- Summary transactions, as for normal Check/Reservation packets, are derived
2529 -- through the summarization logic in glxfss(). This is feasible because of
2530 -- the tightly coupled locking mechanism between the Funds Checker and the
2531 -- Add/Delete Summary Accounts program, and the packet resummarization
2532 -- logic in glxfrs(), which guarantees that all summary lines in all the
2533 -- approved packets will always reflect the most current summarization
2534 -- structures defined
2535
2536 -- Validations normally performed for a Check/Reservation packet in glxfss()
2537 -- denormalization logic are ignored here. Any validation violations that
2538 -- that arise after the Original Packet has been successfully reserved are
2539 -- assumed to be insignificant as these reversal entries are only intended to
2540 -- back out Funds that have been Reserved but is not used for posting
2541
2542 FUNCTION glxfiu RETURN BOOLEAN IS
2543
2544 cursor pkt_id is
2545 select gl_bc_packets_s.nextval
2546 from dual;
2547
2548 l_dummy VARCHAR2(80);
2549
2550 -- ========================= FND LOG ===========================
2551 l_full_path VARCHAR2(100);
2552 -- ========================= FND LOG ===========================
2553 BEGIN
2554
2555 l_full_path := g_path || 'glxfiu.';
2556
2557 -- =========================== FND LOG ===========================
2558 psa_utils.debug_other_string(g_state_level,l_full_path, ' GLXFUI - START' );
2559 -- ========================= FND LOG =============================
2560
2561 open pkt_id;
2562 fetch pkt_id into g_packet_id;
2563 close pkt_id;
2564
2565 -- =========================== FND LOG ===========================
2566 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_packet_id -> ' || g_packet_id );
2567 -- ========================= FND LOG =============================
2568
2569 -- Insert Unreservation Packet into gl_bc_packets
2570 insert into gl_bc_packets
2571 (packet_id,
2572 ledger_id,
2573 je_source_name,
2574 je_category_name,
2575 code_combination_id,
2576 actual_flag,
2577 period_name,
2578 period_year,
2579 period_num,
2580 quarter_num,
2581 currency_code,
2582 status_code,
2583 last_update_date,
2584 last_updated_by,
2585 budget_version_id,
2586 encumbrance_type_id,
2587 entered_dr,
2588 entered_cr,
2589 accounted_dr,
2590 accounted_cr,
2591 ussgl_transaction_code,
2592 originating_rowid,
2593 automatic_encumbrance_flag,
2594 funding_budget_version_id,
2595 funds_check_level_code,
2596 amount_type,
2597 boundary_code,
2598 tolerance_percentage,
2599 tolerance_amount,
2600 override_amount,
2601 account_type,
2602 dr_cr_code,
2603 account_category_code,
2604 effect_on_funds_code,
2605 je_batch_id,
2606 je_header_id,
2607 je_line_num,
2608 ussgl_parent_id,
2609 ussgl_link_to_parent_id,
2610 session_id,
2611 serial_id,
2612 application_id)
2613 select g_packet_id,
2614 bp.ledger_id,
2615 bp.je_source_name,
2616 bp.je_category_name,
2617 bp.code_combination_id,
2618 bp.actual_flag,
2619 bp.period_name,
2620 bp.period_year,
2621 bp.period_num,
2622 bp.quarter_num,
2623 bp.currency_code,
2624 'P',
2625 sysdate,
2626 g_user_id,
2627 bp.budget_version_id,
2628 bp.encumbrance_type_id,
2629 bp.entered_cr,
2630 bp.entered_dr,
2631 bp.accounted_cr,
2632 bp.accounted_dr,
2633 bp.ussgl_transaction_code,
2634 nvl(bp.originating_rowid,
2635 decode(bp.ussgl_transaction_code, NULL, NULL, bp.rowid)),
2636 -- decode(bp.account_type, 'C', g_budgetary_enc_flag,
2637 -- 'D', g_budgetary_enc_flag,
2638 -- nvl(ba.automatic_encumbrance_flag,
2639 -- bp.automatic_encumbrance_flag)),
2640 'Y',
2641 nvl(bo.funding_budget_version_id, bp.funding_budget_version_id),
2642 decode(bo.funds_check_level_code, null,
2643 bp.funds_check_level_code,
2644 'D', nvl(od.funds_check_level_code, 'D'),
2645 bo.funds_check_level_code),
2646 nvl(bo.amount_type, bp.amount_type),
2647 nvl(bo.boundary_code, bp.boundary_code),
2648 od.tolerance_percentage,
2649 od.tolerance_amount,
2650 od.override_amount,
2651 bp.account_type,
2652 bp.dr_cr_code,
2653 bp.account_category_code,
2654 decode(
2655 decode(bp.actual_flag || bp.dr_cr_code ||
2656 bp.account_category_code, 'BCP', 'dec', 'ADP', 'dec',
2657 'EDP', 'dec', 'ACB', 'dec', 'BCB', 'n/a', 'BDB', 'n/a',
2658 'ECB', 'n/a', 'EDB', 'n/a',
2659 'PDP', 'dec',
2660 'PCB', 'dec', 'FDP', 'dec','FCB', 'n/a', 'FDB','n/a','inc'
2661 ),
2662 'dec', decode(sign(nvl(bp.accounted_cr, 0) -
2663 nvl(bp.accounted_dr, 0)), 1, 'D', 'I'),
2664 'inc', decode(sign(nvl(bp.accounted_cr, 0) -
2665 nvl(bp.accounted_dr, 0)), -1, 'D', 'I'),
2666 'n/a', 'I'),
2667 bp.je_batch_id,
2668 bp.je_header_id,
2669 bp.je_line_num,
2670 bp.ussgl_parent_id,
2671 bp.ussgl_link_to_parent_id,
2672 g_session_id,
2673 g_serial_id,
2674 g_resp_appl_id
2675 from psa_option_details_gt od,
2676 gl_budget_assignments ba,
2677 gl_bc_packets bp,
2678 gl_budorg_bc_options bo
2679 where (od.je_source_name || ';' || od.je_category_name =
2680 bp.je_source_name || ';' ||bp.je_category_name )
2681 and od.packet_id = bp.packet_id
2682 and ba.ledger_id (+) = g_ledger_id
2683 and ba.currency_code (+) = bp.currency_code
2684 and ba.code_combination_id (+) = bp.code_combination_id
2685 and bo.range_id(+) = ba.range_id
2686 and bo.funding_budget_version_id
2687 in (select BV1.budget_version_id
2688 from gl_budget_versions bv1, gl_budgets b,
2689 gl_period_statuses ps
2690 where ba.ledger_id = g_ledger_id
2691 and ba.currency_code = bp.currency_code
2692 and ba.code_combination_id = bp.code_combination_id
2693 and b.budget_name = bv1.budget_name
2694 and ((b.budget_type = 'payment'
2695 and bp.actual_flag in ('P', 'F'))
2696 or
2697 (b.budget_type = 'standard'
2698 and bp.actual_flag not in ('P', 'F')))
2699 and ps.application_id = 101
2700 and ps.ledger_id = g_ledger_id
2701 and ps.period_name = bp.period_name
2702 and ps.start_date
2703 >= (select p1.start_date
2704 from gl_period_statuses p1
2705 where p1.period_name = b.first_valid_period_name
2706 and p1.application_id = ps.application_id
2707 and p1.ledger_id = ps.ledger_id)
2708 and ps.end_date
2709 <= (select p2.end_date
2710 from gl_period_statuses p2
2711 where p2.period_name = b.last_valid_period_name
2712 and p2.application_id = ps.application_id
2713 and p2.ledger_id = ps.ledger_id))
2714 and bp.packet_id = g_packet_id_ursvd
2715 and bp.template_id is null
2716 and bp.status_code = 'A';
2717
2718 -- =========================== FND LOG ===========================
2719 psa_utils.debug_other_string(g_state_level,l_full_path, ' Insert gl_bc_packets -> ' || SQL%ROWCOUNT );
2720 -- ========================= FND LOG =============================
2721
2722 BEGIN
2723
2724 SELECT
2725 'There are USSGL rows in the packet'
2726 INTO
2727 l_dummy
2728 FROM
2729 DUAL
2730 WHERE EXISTS
2731 (
2732 SELECT
2733 'Record with non-null USSGL transaction code'
2734 FROM
2735 GL_BC_PACKETS BP
2736 WHERE
2737 BP.packet_id = g_packet_id_ursvd
2738 AND BP.ussgl_transaction_code IS NOT NULL
2739 );
2740
2741 g_append_je_flag := TRUE;
2742
2743 -- =========================== FND LOG ===========================
2744 psa_utils.debug_other_string(g_state_level,l_full_path, ' l_dummy -> ' || l_dummy );
2745 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_append_je_flag -> TRUE');
2746 -- ========================= FND LOG =============================
2747
2748 EXCEPTION
2749 WHEN OTHERS THEN
2750
2751 -- =========================== FND LOG ===========================
2752 psa_utils.debug_other_string(g_excep_level,l_full_path, ' g_append_je_flag -> FALSE');
2753 -- ========================= FND LOG =============================
2754
2755 g_append_je_flag := FALSE;
2756 END;
2757
2758 -- =========================== FND LOG ===========================
2759 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN -> TRUE ' );
2760 -- ========================= FND LOG =============================
2761
2762 return(TRUE);
2763
2764 EXCEPTION
2765
2766 WHEN OTHERS THEN
2767 -- =========================== FND LOG ===========================
2768 psa_utils.debug_other_string(g_excep_level,l_full_path, ' EXCEPTION WHEN OTHERS - ' || SQLERRM );
2769 -- ========================= FND LOG =============================
2770
2771 if pkt_id%ISOPEN then
2772 close pkt_id;
2773 end if;
2774
2775 message_token('PROCEDURE', 'Funds Checker');
2776 message_token('EVENT', SQLERRM);
2777 add_message('SQLGL', 'GL_UNHANDLED_EXCEPTION');
2778
2779 -- =========================== FND LOG ===========================
2780 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN -> FALSE');
2781 -- ========================= FND LOG =============================
2782
2783 g_debug := g_debug||'GLXFIU Failed : '||SQLERRM;
2784
2785 return(FALSE);
2786
2787 END glxfiu;
2788
2789 /* ============================= GLXFSS ============================== */
2790
2791 -- Setup and Summarization
2792
2793 -- This Module sets up the denormalized columns in the queue such as
2794 -- Budgetary Control Options, Funds Check Level, Account Type, Transaction
2795 -- effect on Funds Available, etc. It also validates the Accounting
2796 -- Flexfield and Period info, inserts Summary Transactions into the queue
2797 -- and also inserts the arrival sequence of the packet
2798
2799 FUNCTION glxfss RETURN BOOLEAN IS
2800
2801 sql_bcp VARCHAR2(5000);
2802 str_bc_option_id VARCHAR2(128);
2803
2804 cursor arrseq is
2805 select gl_bc_packet_arrival_order_s.nextval
2806 from dual;
2807
2808 cursor lock_gl_conc_ctrl is
2809 select 'Obtain Row Share Lock on the corresponding record for this Set of Books'
2810 from gl_concurrency_control ct
2811 where ct.concurrency_class = 'INSERT_PACKET_ARRIVAL'
2812 and ct.concurrency_entity_name = 'SET_OF_BOOKS'
2813 and ct.concurrency_entity_id = to_char(g_ledger_id)
2814 FOR UPDATE;
2815
2816 l_dummy varchar2(100);
2817
2818 OVERLAPPING_BUDGET EXCEPTION;
2819 PRAGMA EXCEPTION_INIT(OVERLAPPING_BUDGET,-1427);
2820
2821
2822 -- ========================= FND LOG ===========================
2823 l_full_path VARCHAR2(100);
2824 -- ========================= FND LOG ===========================
2825 BEGIN
2826
2827 l_full_path := g_path || 'glxfss.';
2828
2829 -- =========================== FND LOG ===========================
2830 psa_utils.debug_other_string(g_state_level,l_full_path, ' GLXFSS - START' );
2831 -- ========================= FND LOG =============================
2832
2833 -- Denormalized Columns are not updated if mode is Unreservation since
2834 -- this is handled in glxfiu()
2835
2836 -- ========================= FND LOG =============================
2837 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_fcmode -> ' || g_fcmode);
2838 -- ========================= FND LOG =============================
2839
2840 if g_fcmode <> 'U' then
2841
2842 -- Update denormalized columns for all detail transactions in the packet
2843 -- and perform Accounting Flexfield and Period validation as required. In
2844 -- case of error, set the result code to one of the following values :
2845 --
2846 -- Code Explanation
2847 -- ---- ------------------------------------------------------
2848 -- F20 Accounting Flexfield does not exist
2849 -- F21 Accounting Flexfield is disabled or out-of-date
2850 -- F22 Accounting Flexfield does not allow detail posting
2851 -- F23 Accounting Flexfield does not allow detail budget
2852 -- posting
2853 -- F24 Accounting Period does not exist
2854 -- F25 Accounting Period is neither Open nor Future Enterable
2855 -- F26 Accounting Period is not within an Open budget year
2856 -- F27 Budget is Frozen
2857 -- F28 USSGL Transaction Code is out-of-date
2858
2859
2860 begin
2861
2862 update gl_bc_packets bp
2863 set bp.funding_budget_version_id =
2864 (select decode(pk.actual_flag, 'B', pk.budget_version_id,
2865 bo.funding_budget_version_id)
2866 from gl_budget_assignments ba,
2867 gl_budgets b,
2868 gl_budget_versions bv,
2869 gl_period_statuses ps,
2870 gl_bc_packets pk,
2871 gl_budorg_bc_options bo
2872 where
2873 ba.ledger_id(+) = g_ledger_id
2874 and ba.currency_code(+) = decode(PK.currency_code,
2875 'STAT', 'STAT',
2876 g_func_curr_code)
2877 and ba.code_combination_id (+) = PK.code_combination_id
2878 and bo.range_id(+) = ba.range_id
2879 and bo.funding_budget_version_id = bv.budget_version_id
2880 and bv.budget_name = b.budget_name
2881 and ((b.budget_type = 'payment' and
2882 pk.actual_flag IN ('P', 'F'))
2883 or
2884 (b.budget_type = 'standard' and
2885 pk.actual_flag not in ('P', 'F')))
2886 and ps.application_id = 101
2887 and ps.ledger_id = g_ledger_id
2888 and ps.period_name = pk.period_name
2889 and ps.start_date >= (select p1.start_date
2890 from gl_period_statuses p1
2891 where p1.period_name = b.first_valid_period_name
2892 and p1.application_id = ps.application_id
2893 and p1.ledger_id = ps.ledger_id)
2894 and ps.end_date <= (select p2.end_date
2895 from gl_period_statuses p2
2896 where p2.period_name = b.last_valid_period_name
2897 and p2.application_id = ps.application_id
2898 and p2.ledger_id = ps.ledger_id)
2899 and pk.rowid = bp.rowid
2900 )
2901 where bp.packet_id = g_packet_id
2902 and bp.template_id is null
2903 and bp.funding_budget_version_id is null;
2904
2905 EXCEPTION
2906 WHEN OVERLAPPING_BUDGET THEN
2907
2908 -- =========================== FND LOG ===========================
2909 psa_utils.debug_other_string(g_state_level,l_full_path, ' There are multiple overlapping budgets assigned to account');
2910 psa_utils.debug_other_string(g_state_level,l_full_path, ' Update gl_bc_packets 1 updated failed');
2911 psa_utils.debug_other_string(g_state_level,l_full_path, ' Updating the status code = F/R based on g_fcmode');
2912 psa_utils.debug_other_string(g_state_level,l_full_path, ' Updating the result code= F77/F80 based on overlapping budget');
2913 -- ========================= FND LOG =============================
2914
2915 update gl_bc_packets bp
2916 set STATUS_CODE = DECODE(g_fcmode,'C','F','R'),
2917 RESULT_CODE=
2918 ( select DECODE(count(bo.FUNDING_BUDGET_VERSION_ID),1,'F77','F80')
2919 from
2920 gl_bc_packets pk,
2921 gl_budget_assignments ba,
2922 gl_budorg_bc_options bo
2923 where
2924 pk.rowid=bp.rowid
2925 and pk.code_combination_id=ba.code_combination_id
2926 and pk.ledger_id = ba.ledger_id
2927 and pk.currency_code = ba.currency_code
2928 and ba.range_id = bo.range_id
2929 )
2930 where
2931 bp.packet_id = g_packet_id;
2932
2933 -- =========================== FND LOG ===========================
2934 psa_utils.debug_other_string(g_state_level,l_full_path, ' Set g_overlapping_budget = TRUE, Return -> TRUE');
2935 -- ========================= FND LOG =============================
2936 g_overlapping_budget:=TRUE;
2937 return(TRUE);
2938 end;
2939
2940
2941 -- =========================== FND LOG ===========================
2942 psa_utils.debug_other_string(g_state_level,l_full_path, ' Update gl_bc_packets 1 updated -> ' || SQL%ROWCOUNT || ' rows');
2943 -- ========================= FND LOG =============================
2944
2945 update gl_bc_packets bp
2946 set (bp.automatic_encumbrance_flag,
2947 bp.funds_check_level_code,
2948 bp.tolerance_percentage,
2949 bp.tolerance_amount,
2950 bp.override_amount,
2951 bp.account_type,
2952 bp.dr_cr_code,
2953 bp.account_category_code,
2954 bp.effect_on_funds_code,
2955 bp.result_code) =
2956 (
2957 select 'Y',
2958 decode(pk.funding_budget_version_id, NULL, 'N', NULL),
2959 od.tolerance_percentage,
2960 od.tolerance_amount,
2961 od.override_amount,
2962 cc.account_type,
2963 decode(cc.account_type, 'A', 'D', 'E', 'D', 'D', 'D', 'C'),
2964 decode(cc.account_type, 'D', 'B', 'C', 'B', 'P'),
2965 decode(
2966 decode(pk.actual_flag || cc.account_type,
2967 'BL', 'dec',
2968 'BO', 'dec',
2969 'BR', 'dec',
2970 'AA', 'dec',
2971 'AE', 'dec',
2972 'EA', 'dec',
2973 'EE', 'dec',
2974 'AC', 'dec',
2975 'BC', 'n/a',
2976 'BD', 'n/a',
2977 'EC', 'n/a',
2978 'ED', 'n/a',
2979 'inc'),
2980 'dec',
2981 decode(sign(nvl(pk.accounted_dr, 0)-
2982 nvl(pk.accounted_cr, 0)), 1, 'D', 'I'),
2983 'inc',
2984 decode(sign(nvl(pk.accounted_dr, 0)-
2985 nvl(pk.accounted_cr, 0)), -1, 'D', 'I'),
2986 'n/a', 'I'),
2987 decode(cc.code_combination_id, null, 'F20',
2988 decode(cc.enabled_flag, 'N', 'F21',
2989 decode(sign(sysdate - nvl(cc.start_date_active,sysdate)),-1,'F21',
2990 decode(sign(nvl(cc.end_date_active,sysdate)-sysdate),-1,'F21',
2991 decode(pk.actual_flag ||
2992 cc.detail_posting_allowed_flag,
2993 'AN', 'F22', 'EN', 'F22',
2994 decode(pk.actual_flag ||
2995 cc.detail_budgeting_allowed_flag,
2996 'BN', 'F23',
2997 decode(ps.period_name, null, 'F24',
2998 decode(pk.actual_flag || ps.closing_status,
2999 'AN', 'F25', 'AC', 'F25', 'AP', 'F25',
3000 decode(pk.actual_flag ||
3001 nvl(br.open_flag, 'N'), 'BN', 'F26',
3002 decode(pk.actual_flag || bv.status,
3003 'BF', 'F27',
3004 decode(sign(nvl(pk.bc_date, sysdate) -
3005 nvl(uc.start_date_active, nvl(pk.bc_date, sysdate))),
3006 -1, 'F28',
3007 decode(sign(nvl(uc.end_date_active,
3008 nvl(pk.bc_date, sysdate)) - nvl(pk.bc_date, sysdate)), -1, 'F28',
3009 decode(substr(pk.result_code,1,1),
3010 'X', 'F' || substr(pk.result_code,2),
3011 null)))))))))))))
3012 from gl_ussgl_transaction_codes uc,
3013 gl_budget_versions bv,
3014 gl_budget_period_ranges br,
3015 gl_period_statuses ps,
3016 gl_code_combinations cc,
3017 psa_option_details_gt od,
3018 gl_bc_packets pk
3019 where uc.chart_of_accounts_id (+) = g_coa_id
3020 and uc.ussgl_transaction_code (+) =
3021 nvl(pk.ussgl_transaction_code, -1)
3022 and bv.budget_version_id (+) = nvl(pk.budget_version_id, -1)
3023 and br.budget_version_id (+) = nvl(pk.budget_version_id, -1)
3024 and br.period_year (+) = pk.period_year
3025 and pk.period_num between br.start_period_num (+)
3026 and br.end_period_num (+)
3027 and ps.application_id (+) = 101
3028 and ps.ledger_id (+) = g_ledger_id
3029 and ps.period_name (+) = pk.period_name
3030 and cc.code_combination_id (+) = pk.code_combination_id
3031 and (od.je_source_name || ';' || od.je_category_name =
3032 pk.je_source_name || ';' || pk.je_category_name )
3033 and od.packet_id = pk.packet_id
3034 and pk.rowid = bp.rowid
3035 )
3036 where bp.packet_id = g_packet_id
3037 and bp.template_id is null;
3038
3039 -- =========================== FND LOG ===========================
3040 psa_utils.debug_other_string(g_state_level,l_full_path, ' Update gl_bc_packets 2 updated -> ' || SQL%ROWCOUNT || ' rows');
3041 -- ========================= FND LOG =============================
3042
3043 update gl_bc_packets bp
3044 set (funds_check_level_code,
3045 amount_type,
3046 boundary_code) = (select
3047 nvl(min(decode(bo.funds_check_level_code, 'D',
3048 nvl(od.funds_check_level_code, 'D'),
3049 nvl(bo.funds_check_level_code, 'N'))), 'N'),
3050 min(bo.amount_type),
3051 min(bo.boundary_code)
3052 from gl_bc_packets pk,
3053 psa_option_details_gt od,
3054 gl_budget_assignments ba,
3055 gl_budorg_bc_options bo
3056 where pk.rowid = bp.rowid
3057 and (od.je_source_name || ';' || od.je_category_name =
3058 pk.je_source_name || ';' || pk.je_category_name )
3059 and od.packet_id = pk.packet_id
3060 and ba.ledger_id = g_ledger_id
3061 and ba.currency_code = decode(pk.currency_code,
3062 'STAT', 'STAT',
3063 g_func_curr_code)
3064 and ba.code_combination_id = pk.code_combination_id
3065 and bo.range_id = ba.range_id
3066 and bo.funding_budget_version_id = pk.funding_budget_version_id)
3067 where bp.packet_id = g_packet_id
3068 and bp.funding_budget_version_id is not null;
3069
3070
3071 -- =========================== FND LOG ===========================
3072 psa_utils.debug_other_string(g_state_level,l_full_path, ' Update gl_bc_packets 3 updated -> ' || SQL%ROWCOUNT || ' rows');
3073 -- ========================= FND LOG =============================
3074
3075
3076 /*----------------------------------------------------------------------+
3077 | Bug 5242198 : When an account is assigned with different funds check |
3078 | level(say Absolute and Advisory) the account is assumed to have a |
3079 | funds check level of absolute with no funding budget for preiods with|
3080 | no budget assignments... |
3081 +----------------------------------------------------------------------*/
3082
3083 if(nvl(g_enable_efc_flag,'N')='Y') THEN
3084 update gl_bc_packets bp
3085 set bp.funds_check_level_code = 'B'
3086 where bp.packet_id = g_packet_id
3087 and bp.template_id is null
3088 and bp.funds_check_level_code = 'N'
3089 and bp.funding_budget_version_id IS NULL
3090 and exists
3091 (select null
3092 from gl_budget_assignments ba
3093 where ba.code_combination_id = bp.code_combination_id
3094 and ba.ledger_id = bp.ledger_id
3095 and ba.currency_code = bp.currency_code
3096
3097 );
3098 end if;
3099 end if; -- g_fcmode <> 'U'
3100
3101
3102 -- Prior to inserting Summary Transactions for the packet, we lock the
3103 -- dummy table gl_bc_dual2 in row share mode to ensure data consistency
3104 -- between the Funds Checker Summarization and the Add/Delete Summary
3105 -- Accounts process. This ensures that that only one process will
3106 -- summarize the transactions in the queue
3107
3108 -- When a lock on gl_bc_dual2 is not available then
3109 --
3110 -- if Funds Checker is invoked from a Concurrent Process, it waits
3111 --
3112 -- if Funds Checker is invoked from an Online Process, it exits with
3113 -- a fatal error
3114
3115
3116 if g_conc_flag then
3117 -- =========================== FND LOG ===========================
3118 psa_utils.debug_other_string(g_state_level,l_full_path,
3119 ' Lock gl_bc_dual2 in row share mode' );
3120 -- ========================= FND LOG =============================
3121 LOCK TABLE gl_bc_dual2 IN ROW SHARE MODE;
3122 else
3123 -- =========================== FND LOG ===========================
3124 psa_utils.debug_other_string(g_state_level,l_full_path,
3125 ' Lock gl_bc_dual2 in row share mode nowait' );
3126 -- ========================= FND LOG =============================
3127 LOCK TABLE gl_bc_dual2 IN ROW SHARE MODE NOWAIT;
3128 end if;
3129
3130
3131 -- Insert Summary Transactions for the Packet. Summarization Grouping is
3132 -- based on Summary Code Combination, Balance Type, Period Name, Currency
3133 -- Code, Encumbrance Type, JE Source, JE Category and Budget Name
3134
3135 -- The Join Condition
3136 --
3137 -- st.account_category_code = bp.account_category_code
3138 --
3139 -- ensures that if a template is Proprietary, Summarization ignore any
3140 -- Budgetary Detail Accounts that may fall into the same Rollup Structure,
3141 -- and vice-versa
3142
3143 insert into gl_bc_packets (packet_id,
3144 ledger_id,
3145 je_source_name,
3146 je_category_name,
3147 code_combination_id,
3148 actual_flag,
3149 period_name,
3150 period_year,
3151 period_num,
3152 quarter_num,
3153 currency_code,
3154 status_code,
3155 last_update_date,
3156 last_updated_by,
3157 budget_version_id,
3158 encumbrance_type_id,
3159 template_id,
3160 entered_dr,
3161 entered_cr,
3162 accounted_dr,
3163 accounted_cr,
3164 funding_budget_version_id,
3165 funds_check_level_code,
3166 amount_type,
3167 boundary_code,
3168 tolerance_percentage,
3169 tolerance_amount,
3170 override_amount,
3171 dr_cr_code,
3172 account_category_code,
3173 effect_on_funds_code,
3174 session_id,
3175 serial_id,
3176 application_id)
3177 select
3178 min(bp.packet_id),
3179 min(bp.ledger_id),
3180 min(bp.je_source_name),
3181 min(bp.je_category_name),
3182 min(ah.summary_code_combination_id),
3183 min(bp.actual_flag),
3184 min(bp.period_name),
3185 min(bp.period_year),
3186 min(bp.period_num),
3187 min(bp.quarter_num),
3188 min(bp.currency_code),
3189 min(bp.status_code),
3190 min(bp.last_update_date),
3191 min(bp.last_updated_by),
3192 min(decode(bp.actual_flag, 'B', bp.budget_version_id, null)),
3193 min(decode(bp.actual_flag, 'E', bp.encumbrance_type_id,null)),
3194 min(st.template_id),
3195 sum(nvl(bp.entered_dr, 0)),
3196 sum(nvl(bp.entered_cr, 0)),
3197 sum(nvl(bp.accounted_dr, 0)),
3198 sum(nvl(bp.accounted_cr, 0)),
3199 min(sb.funding_budget_version_id),
3200 min(decode(sb.funds_check_level_code, 'D',
3201 nvl(od.funds_check_level_code, 'D'),
3202 sb.funds_check_level_code)),
3203 min(sb.amount_type),
3204 min(sb.boundary_code),
3205 min(od.tolerance_percentage),
3206 min(od.tolerance_amount),
3207 min(od.override_amount),
3208 min(sb.dr_cr_code),
3209 min(st.account_category_code),
3210 decode(
3211 decode(min(bp.actual_flag) || min(sb.dr_cr_code) ||
3212 min(st.account_category_code),
3213 'BCP', 'dec', 'ADP', 'dec',
3214 'EDP', 'dec', 'ACB', 'dec', 'BCB',
3215 'n/a', 'BDB', 'n/a',
3216 'ECB', 'n/a', 'EDB', 'n/a', 'inc'),
3217 'dec',
3218 decode(sign(sum(nvl(bp.accounted_dr, 0) -
3219 nvl(bp.accounted_cr, 0))), 1, 'D', 'I'),
3220 'inc',
3221 decode(sign(sum(nvl(bp.accounted_dr, 0) -
3222 nvl(bp.accounted_cr, 0))), -1, 'D', 'I'),
3223 'n/a', 'I'),
3224 min(bp.session_id),
3225 min(bp.serial_id),
3226 min(bp.application_id)
3227 from psa_option_details_gt od,
3228 gl_period_statuses ps,
3229 gl_summary_templates st,
3230 gl_account_hierarchies ah,
3231 gl_bc_packets bp,
3232 gl_summary_bc_options sb,
3233 gl_budgets b,
3234 gl_budget_versions bv,
3235 gl_period_statuses ps2
3236 where st.status = 'F'
3237 and sb.funds_check_level_code || od.funds_check_level_code <> 'DN'
3238 and st.template_id = ah.template_id
3239 and sb.funding_budget_version_id = decode(bp.actual_flag,
3240 'B', bp.budget_version_id,
3241 sb.funding_budget_version_id)
3242 and st.account_category_code = bp.account_category_code
3243 and ps.ledger_id = g_ledger_id
3244 and ps.application_id = 101
3245 and ps.period_name = st.start_actuals_period_name
3246 and (ps.period_year * 10000 + ps.period_num) <=
3247 (bp.period_year * 10000 + bp.period_num)
3248 AND SB.template_id = ST.template_id
3249 AND SB.funding_budget_version_id = BV.budget_version_id
3250 AND BV.budget_name = B.budget_name
3251 AND ((BV.budget_type = 'payment' AND BP.actual_flag in ('P', 'F'))
3252 OR (BV.budget_type = 'standard' AND BP.actual_flag in ('A', 'E'))
3253 OR (BP.actual_flag = 'B'))
3254 and ps2.ledger_id = g_ledger_id
3255 and ps2.application_id = 101
3256 AND PS2.period_name = BP.period_name
3257 AND PS2.start_date >= (select P1.start_date
3258 from GL_PERIOD_STATUSES P1
3259 where P1.application_id = ps2.application_id
3260 and P1.ledger_id = ps2.ledger_id
3261 and P1.period_name = B.first_valid_period_name)
3262 AND PS2.end_date <= (select P2.end_date
3263 from GL_PERIOD_STATUSES P2
3264 where P2.application_id = ps2.application_id
3265 and P2.ledger_id = ps2.ledger_id
3266 and P2.period_name = B.last_valid_period_name)
3267 and ah.ledger_id = g_ledger_id
3268 and ah.detail_code_combination_id = bp.code_combination_id
3269 and od.packet_id = bp.packet_id
3270 and od.je_source_name || ';' || od.je_category_name =
3271 bp.je_source_name || ';' || bp.je_category_name
3272 and (bp.je_batch_id is not null
3273 or bp.automatic_encumbrance_flag = 'Y'
3274 or bp.actual_flag <> 'E')
3275 and bp.packet_id = g_packet_id
3276 and bp.result_code is null
3277 group by ah.summary_code_combination_id,
3278 bp.actual_flag,
3279 bp.period_name,
3280 bp.encumbrance_type_id,
3281 bp.period_num, -- Bug 3259452
3282 bp.currency_code,
3283 bp.je_source_name,
3284 bp.je_category_name,
3285 bp.budget_version_id
3286 having sum(nvl(bp.accounted_dr, 0) - nvl(bp.accounted_cr, 0)) <> 0;
3287
3288
3289
3290 -- Set Summarized Flag if Summary Transactions were inserted into the queue
3291
3292 if SQL%FOUND then
3293 -- =========================== FND LOG ===========================
3294 psa_utils.debug_other_string(g_state_level,l_full_path,
3295 ' Insert gl_bc_packets - summ trans ' || SQL%ROWCOUNT );
3296
3297 psa_utils.debug_other_string(g_state_level,l_full_path,
3298 ' g_summarized_flag -> TRUE' );
3299 -- ========================= FND LOG =============================
3300 g_summarized_flag := TRUE;
3301 end if;
3302
3303
3304 -- Insert Arrival Sequence for the Packet. The Row Share Lock ensures that
3305 -- packets are assigned sequences strictly in order of arrival
3306
3307 -- When a lock on gl_concurrency_control is not available then
3308 --
3309 -- if Funds Checker is invoked from a Concurrent Process, it waits
3310 --
3311 -- if Funds Checker is invoked from an Online Process, it exits with
3312 -- an error
3313
3314 if g_conc_flag then
3315 -- =========================== FND LOG ===========================
3316 psa_utils.debug_other_string(g_state_level,l_full_path,
3317 ' g_conc_flag -> TRUE' );
3318 -- ========================= FND LOG =============================
3319
3320 open lock_gl_conc_ctrl;
3321 fetch lock_gl_conc_ctrl into l_dummy;
3322 close lock_gl_conc_ctrl;
3323
3324 end if;
3325
3326
3327 -- Get Arrival Sequence
3328
3329 open arrseq;
3330 fetch arrseq into g_arrival_seq;
3331 close arrseq;
3332
3333 -- =========================== FND LOG ===========================
3334 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_arrival_seq -> ' || g_arrival_seq);
3335 -- ========================= FND LOG =============================
3336
3337 insert into gl_bc_packet_arrival_order
3338 (packet_id,
3339 ledger_id,
3340 arrival_seq,
3341 affect_funds_flag,
3342 last_update_date,
3343 last_updated_by)
3344 values (g_packet_id,
3345 g_ledger_id,
3346 g_arrival_seq,
3347 decode(g_fcmode, 'C', 'N', 'Y'),
3348 sysdate,
3349 g_user_id);
3350
3351
3352 -- =========================== FND LOG ===========================
3353 psa_utils.debug_other_string(g_state_level,l_full_path,
3354 ' insert gl_bc_packet_arrival_order -> ' || SQL%ROWCOUNT);
3355 -- ========================= FND LOG =============================
3356
3357 -- Commit to release Lock on gl_concurrency_control
3358 commit;
3359
3360
3361 -- Since the previous Commit has also released the lock on gl_bc_dual2, we
3362 -- need to reestablish the lock to maintain data consistency between the
3363 -- Funds Checker Summarization and the Add/Delete Summary Accounts
3364 -- process
3365
3366 -- =========================== FND LOG ===========================
3367 psa_utils.debug_other_string(g_state_level,l_full_path,
3368 ' lock table gl_bc_dual2 in row share mode nowait');
3369 -- ========================= FND LOG =============================
3370
3371 LOCK TABLE gl_bc_dual2 IN ROW SHARE MODE NOWAIT;
3372
3373 -- =========================== FND LOG ===========================
3374 psa_utils.debug_other_string(g_state_level,l_full_path,
3375 ' RETURN -> TRUE ');
3376 -- ========================= FND LOG =============================
3377
3378 return(TRUE);
3379
3380 EXCEPTION
3381
3382 WHEN OTHERS THEN
3383
3384 -- =========================== FND LOG ===========================
3385 psa_utils.debug_other_string(g_excep_level,l_full_path, ' EXCEPTION WHEN OTHERS ' || SQLERRM);
3386 -- ========================= FND LOG =============================
3387
3388 if arrseq%ISOPEN then
3389 close arrseq;
3390 end if;
3391
3392 if SQLCODE = -54 then
3393 message_token('PROCEDURE', 'Funds Checker');
3394 message_token('EVENT', 'Table Locked by Add/Delete Summary Accounts Process');
3395 add_message('SQLGL', 'GL_UNHANDLED_EXCEPTION');
3396 else
3397 message_token('PROCEDURE', 'Funds Checker');
3398 message_token('EVENT', SQLERRM);
3399 add_message('SQLGL', 'GL_UNHANDLED_EXCEPTION');
3400 end if;
3401
3402 -- =========================== FND LOG ===========================
3403 psa_utils.debug_other_string(g_excep_level,l_full_path, ' RETURN -> FALSE');
3404 -- ========================= FND LOG =============================
3405 g_debug := g_debug||'GLXFSS Failed : '||SQLERRM;
3406
3407 return(FALSE);
3408
3409 END glxfss;
3410
3411 /* ============================= GLXFGB =========================== */
3412
3413 -- Process Balances
3414 -- Find Pending and Approved Actual, Budget and Encumbrance transaction
3415 -- balances in the queue that would affect funds availability for the
3416 -- transactions in this packet
3417 -- Find the posted actual, budget and encumbrance balances in the balances
3418 -- table that would affect funds availability for the transactions in this
3419 -- packet
3420
3421 FUNCTION glxfgb RETURN BOOLEAN IS
3422
3423 -- Bug 3574935
3424
3425 --Bug 6823089 ..
3426 --l_max_packet_id gl_bc_packets.packet_id%type;
3427
3428 -- Bug 5644702
3429 l_effective_period_num gl_period_statuses.effective_period_num%TYPE;
3430 l_period_name gl_period_statuses.period_name%TYPE;
3431 l_quarter_num gl_period_statuses.quarter_num%TYPE;
3432 l_period_year gl_period_statuses.period_year%TYPE;
3433
3434 resource_busy exception;
3435 l_psa_max_lock_wait_count fnd_profile_option_values.profile_option_value%TYPE :=0;
3436 l_psa_lock_wait_interval fnd_profile_option_values.profile_option_value%TYPE :=0;
3437 pragma exception_init(resource_busy, -54);
3438 -- ========================= FND LOG ===========================
3439 l_full_path VARCHAR2(100);
3440 -- ========================= FND LOG ===========================
3441 BEGIN
3442
3443 l_full_path := g_path || 'glxfgb';
3444
3445 -- =========================== FND LOG ===========================
3446 psa_utils.debug_other_string(g_state_level,l_full_path, ' GLXFGB - START' );
3447 -- ========================= FND LOG =============================
3448
3449 --Added below code for bug 9907009 --GNRAJAGO
3450 FND_PROFILE.GET('PSA_MAX_LOCK_WAIT_COUNT', l_psa_max_lock_wait_count);
3451 IF (l_psa_max_lock_wait_count IS NULL) THEN
3452 l_psa_max_lock_wait_count := 0;
3453 END IF;
3454
3455 FND_PROFILE.GET('PSA_LOCK_WAIT_INTERVAL', l_psa_lock_wait_interval);
3456 IF (l_psa_lock_wait_interval IS NULL) THEN
3457 l_psa_lock_wait_interval := 0;
3458 END IF;
3459
3460 -- =========================== FND LOG ===========================
3461 psa_utils.debug_other_string(g_state_level,l_full_path,
3462 ' Profile PSA_MAX_LOCK_WAIT_COUNT Value is '|| l_psa_max_lock_wait_count);
3463 psa_utils.debug_other_string(g_state_level,l_full_path,
3464 ' Profile PSA_LOCK_WAIT_INTERVAL Value is '||l_psa_lock_wait_interval);
3465 -- ========================= FND LOG =============================
3466
3467 -- Bug 3574935 .. Start
3468 -- Obtain the maximum packet_id less than the current arrival sequence from
3469 -- table gl_bc_packet_arrival_order. This will then be used in the following
3470 -- UPDATE statement to help improve performance of the query. Making use of
3471 -- packet_id condition in the subquery makes index gl_bc_packets_n2 more
3472 -- selective and reduces number of rows processed during access to the table
3473 -- gl_bc_packet_arrival_order
3474
3475 -- Bug 4651919 .. Start
3476 -- Added ledger_id and affect_funds_flag conditions in WHERE clause
3477
3478 -- Bug 6823089.
3479 -- SELECT max(packet_id) INTO l_max_packet_id
3480 -- FROM gl_bc_packet_arrival_order
3481 -- WHERE arrival_seq < g_arrival_seq
3482 -- AND ledger_id = g_ledger_id;
3483 -- AND affect_funds_flag = 'Y';
3484
3485 -- Bug 4651919 .. End
3486
3487 -- Bug 3574935 .. End
3488
3489 -- =========================== FND LOG ===========================
3490 -- psa_utils.debug_other_string(g_state_level,l_full_path, ' l_max_packet_id -> '|| l_max_packet_id );
3491 -- ========================= FND LOG =============================
3492
3493 -- Lock dummy table gl_bc_dual in Row Share Mode to ensure Read Consistency
3494 -- between gl_bc_packets and gl_balances in the next two balance update
3495 -- SQLs. This scheme requires posting to lock gl_bc_dual in exclusive mode
3496 -- before it commits, and to wait in a sleep cycle of 15 seconds until all
3497 -- the Funds Check processes release the locks. This prevents the Funds
3498 -- Checker from counting the Balances twice, in case Posting Commits in
3499 -- between the two SQLs, and some of the pending balances got transferred
3500 -- to gl_balances, where the funds checker would mistakenly treat them as
3501 -- Posted Balances in the second SQL
3502
3503 -- When a lock on gl_bc_dual is not available then
3504 --
3505 -- if Funds Checker is invoked from a Concurrent Process, it waits
3506 --
3507 -- if Funds Checker is invoked from an Online Process, it exits with
3508 -- a fatal error
3509 --Commented out below section for bug 9907009. Changed lock mode to row share.
3510 -- if g_conc_flag then
3511 -- =========================== FND LOG ===========================
3512 -- psa_utils.debug_other_string(g_state_level,l_full_path,
3513 -- ' Lock table gl_bc_dual in exclusive mode' );
3514 -- ========================= FND LOG =============================
3515 -- LOCK TABLE gl_bc_dual IN EXCLUSIVE MODE; --Bug 7476309
3516 -- else
3517 -- =========================== FND LOG ===========================
3518 -- psa_utils.debug_other_string(g_state_level,l_full_path,
3519 -- ' Lock table gl_bc_dual in exclusive mode NOWAIT' );
3520 -- ========================= FND LOG =============================
3521 -- LOCK TABLE gl_bc_dual IN EXCLUSIVE MODE NOWAIT; --Bug 7476309
3522 -- end if;
3523 -- Added below section for bug 9907009.
3524
3525 IF g_conc_flag THEN
3526
3527 LOCK TABLE gl_bc_dual IN ROW SHARE MODE;
3528 -- =========================== FND LOG ===========================
3529 psa_utils.debug_other_string(g_state_level,l_full_path,
3530 ' Lock table gl_bc_dual in row share mode' );
3531 -- ========================= FND LOG =============================
3532 ELSE
3533 LOOP
3534 BEGIN
3535 -- =========================== FND LOG ===========================
3536 psa_utils.debug_other_string(g_state_level,l_full_path,
3537 ' Lock table gl_bc_dual in row share mode NOWAIT, Try count left '||l_psa_max_lock_wait_count );
3538 -- ========================= FND LOG =============================
3539 LOCK TABLE gl_bc_dual IN ROW SHARE MODE NOWAIT;
3540 exit;
3541
3542 EXCEPTION when resource_busy then
3543 -- =========================== FND LOG ===========================
3544 psa_utils.debug_other_string(g_state_level,l_full_path,
3545 ' Resource_busy exception, sleeping for '||l_psa_lock_wait_interval||' seconds');
3546 l_psa_max_lock_wait_count := l_psa_max_lock_wait_count - 1;
3547 dbms_lock.sleep(l_psa_lock_wait_interval);
3548
3549 -- ========================= FND LOG =============================
3550 IF (l_psa_max_lock_wait_count<=0) THEN
3551 -- =========================== FND LOG ===========================
3552 psa_utils.debug_other_string(g_state_level,l_full_path,
3553 ' PSA_MAX_LOCK_WAIT_COUNT reached, raising resource_busy exception');
3554 -- ========================= FND LOG =============================
3555 fnd_file.put_line(fnd_file.output, 'Failed to acquire lock on gl_bc_dual table');
3556 fnd_file.put_line(fnd_file.output, 'Increase the following profile values and retry.');
3557 fnd_file.put_line(fnd_file.output, 'PSA: Budgetary Control Acquire Dual Lock Retry Count');
3558 fnd_file.put_line(fnd_file.output, 'PSA: Budgetary Control Acquire Dual Lock Wait Interval');
3559 RAISE resource_busy;
3560 END IF;
3561 END;
3562 END LOOP;
3563 END IF;
3564
3565 -- Update Approved and Pending Balances in gl_bc_packets
3566 --
3567 -- Transactions in the gl_bc_packets that would affect the transactions in
3568 -- this packet are :
3569 --
3570 -- all approved packets, for the same Set of Books, that arrived earlier
3571 --
3572 -- all pending packets, for the same Set of Books, that arrived earlier
3573 -- and which reduce Funds Available
3574 --
3575 -- all rows in the current packet that have a lower combined score of
3576 -- Rank(Funds Check Level) || Rowid than the row currently being
3577 -- processed
3578 --
3579 -- all transactions in the current packet that would increase funds
3580 -- available
3581
3582 -- Summary of Funds Check Level Rank :
3583 --
3584 -- Funds Check Level Rank
3585 -- ----------------- ----
3586 -- None (N) 0
3587 -- Advisory (D) 1
3588 -- Absolute (B) 2
3589 --
3590 -- For example, when processing an Advisory Transaction, rows in the same
3591 -- packet that need to be considered in this category include all rows
3592 -- with Funds Check Level None, and all Advisory Transactions with a
3593 -- lower rowid than that of the row currently being processed
3594
3595 -- Subquery needs to join to gl_budgets, gl_budget_versions and
3596 -- gl_period_statuses to get the last period in the latest open year of
3597 -- the Funding Budget for the Boundary Code 'project'
3598
3599 -- Summary of WHERE clauses based on Amount Type and Boundary :
3600 --
3601 -- Amount Type Where Clauses
3602 -- ----------- -------------
3603 -- PTD where p2.period_year = p1.period_year
3604 -- and p2.period_num = p1.period_num
3605 --
3606 -- QTD where p2.period_year = p1.period_year
3607 -- and p2.quarter_num = p1.quarter_num
3608 --
3609 -- YTD where p2.period_year = p1.period_year
3610 --
3611 -- PJTD <no restriction>
3612 --
3613 -- Boundary Where Clauses
3614 -- -------- -------------
3615 -- Period and ((p2.period_year = p1.period_year
3616 -- and p2.period_num <= p1.period_num)
3617 -- or (p2.period_year < p1.period_year))
3618 --
3619 -- Quarter and ((p2.period_year = p1.period_year
3620 -- and p2.quarter_num <= p1.quarter_num)
3621 -- or (p2.period_year < p1.period_year))
3622 --
3623 -- Year and p2.period_year <= p1.period_year
3624 --
3625 -- Project and ((p2.period_year = EOB.period_year
3626 -- and p2.period_num <= EOB.period_num)
3627 -- or (p2.period_year < EOB.period_year))
3628 -- EOB = Last Period in Latest Open Year of Budget
3629
3630
3631 update
3632 gl_bc_packets bp
3633 set (bp.budget_approved_balance,
3634 bp.actual_approved_balance,
3635 bp.encumbrance_approved_balance,
3636 bp.budget_pending_balance,
3637 bp.actual_pending_balance,
3638 bp.encumbrance_pending_balance) =
3639 (
3640 select
3641 sum(decode(pk.status_code || pk.actual_flag,
3642 'AB', nvl(pk.accounted_dr, 0) - nvl(pk.accounted_cr, 0),
3643 0)
3644 ),
3645 sum(decode(pk.status_code || pk.actual_flag,
3646 'AA', nvl(pk.accounted_dr, 0) - nvl(pk.accounted_cr, 0),
3647 0)
3648 ),
3649 sum(decode(pk.status_code || pk.actual_flag,
3650 'AE', nvl(pk.accounted_dr, 0) - nvl(pk.accounted_cr, 0),
3651 0)
3652 ),
3653 sum(decode(pk.status_code || pk.actual_flag,
3654 'PB', nvl(pk.accounted_dr, 0) - nvl(pk.accounted_cr, 0),
3655 'CB', nvl(pk.accounted_dr, 0) - nvl(pk.accounted_cr, 0),
3656 0)
3657 ),
3658 sum(decode(pk.status_code || pk.actual_flag,
3659 'PA', nvl(pk.accounted_dr, 0) - nvl(pk.accounted_cr, 0),
3660 'CA', nvl(pk.accounted_dr, 0) - nvl(pk.accounted_cr, 0),
3661 0)
3662 ),
3663 sum(decode(pk.status_code || pk.actual_flag,
3664 'PE', nvl(pk.accounted_dr, 0) - nvl(pk.accounted_cr, 0),
3665 'CE', nvl(pk.accounted_dr, 0) - nvl(pk.accounted_cr, 0),
3666 0)
3667 )
3668 from gl_period_statuses ps,
3669 gl_budgets bd,
3670 gl_budget_versions bv,
3671 gl_bc_packets pk,
3672 gl_bc_packet_arrival_order ao
3673 where ps.application_id = 101
3674 and ps.ledger_id = g_ledger_id
3675 and ps.period_name = bd.last_valid_period_name
3676 and bd.budget_name = bv.budget_name
3677 and bd.budget_type = bv.budget_type
3678 and bv.budget_version_id = bp.funding_budget_version_id
3679 and pk.funding_budget_version_id = bp.funding_budget_version_id
3680 and pk.ledger_id = g_ledger_id
3681 and pk.code_combination_id = bp.code_combination_id
3682 and (pk.budget_version_id is null
3683 or pk.budget_version_id = bp.funding_budget_version_id)
3684 and pk.period_year = decode(bp.amount_type, 'PJTD',
3685 pk.period_year, bp.period_year)
3686 and pk.period_num = decode(bp.amount_type, 'PTD',
3687 bp.period_num, pk.period_num)
3688 and pk.quarter_num = decode(bp.amount_type, 'QTD',
3689 bp.quarter_num, pk.quarter_num)
3690 and ((pk.period_year = decode(bp.boundary_code,
3691 'J', bd.latest_opened_year,
3692 bp.period_year)
3693 and pk.period_num <= decode(bp.boundary_code, 'P',
3694 bp.period_num, 'J',
3695 decode(ps.period_year,
3696 bd.latest_opened_year,
3697 ps.period_num,
3698 pk.period_num), pk.period_num)
3699 and pk.quarter_num <= decode(bp.boundary_code, 'Q',
3700 bp.quarter_num, pk.quarter_num))
3701 or pk.period_year < decode(bp.boundary_code, 'J',
3702 bd.latest_opened_year,
3703 bp.period_year))
3704 and pk.currency_code = decode(pk.actual_flag, 'B',
3705 g_func_curr_code, pk.currency_code)
3706 and pk.packet_id = ao.packet_id
3707 and ((pk.packet_id = g_packet_id -- Bug 3574935
3708 and (decode(pk.funds_check_level_code, 'N', '0', 'D', '1',
3709 'B', '2') || pk.rowid <
3710 decode(bp.funds_check_level_code, 'N', '0', 'D', '1',
3711 'B', '2') || bp.rowid
3712 or pk.effect_on_funds_code = 'I'))
3713
3714 --Bug 6823089.. Start
3715 -- or (pk.packet_id <= l_max_packet_id -- Bug 3574935, Bug 4119217
3716 or(pk.packet_id >=0 and pk.status_code = 'A') --Bug 7476309
3717 or (pk.packet_id >= 0
3718 --Bug 6823089.. End
3719
3720 and ao.arrival_seq < g_arrival_seq
3721 -- and ao.affect_funds_flag = 'Y'
3722 and ao.ledger_id = g_ledger_id
3723 and nvl(pk.result_code, 'X') like
3724 decode(pk.status_code, 'A', 'P%', 'P', 'P%', 'C', 'P%', 'X') -- Bug 4630687
3725 -- Bug 5046369 start
3726 and (
3727 (pk.status_code IN ('P', 'C')
3728 and exists (select 'Packet is valid for the current session'
3729 from v$session s
3730 WHERE s.audsid = pk.session_id
3731 AND s.serial# = pk.serial_id)
3732 )
3733 OR
3734 pk.status_code = 'A'
3735 )))
3736 -- rgopalan Bug 2799257
3737 and EXISTS
3738 (SELECT 'x' FROM fnd_currencies
3739 WHERE currency_code = PK.currency_code
3740 AND currency_flag = 'Y')
3741 )
3742 where bp.packet_id = g_packet_id
3743 and bp.result_code is null
3744 and bp.effect_on_funds_code = 'D'
3745 and bp.funds_check_level_code <> 'N'
3746 and bp.currency_code = decode(bp.actual_flag, 'B', g_func_curr_code,
3747 bp.currency_code)
3748 and bp.funding_budget_version_id = decode(bp.actual_flag, 'B',
3749 bp.budget_version_id,
3750 bp.funding_budget_version_id)
3751 -- rgopalan Bug 27992557
3752 and exists
3753 (SELECT 'x' FROM fnd_currencies
3754 WHERE currency_code = BP.currency_code
3755 AND currency_flag = 'Y');
3756
3757
3758 -- =========================== FND LOG ===========================
3759 psa_utils.debug_other_string(g_state_level,l_full_path,
3760 ' Update approved and pending balance in gl_bc_packets ' || SQL%ROWCOUNT );
3761 -- ========================= FND LOG =============================
3762
3763
3764 -- Update Posted Balances in gl_bc_packets
3765 --
3766 -- For Actuals, we subtract the begin balances of the first period of the
3767 -- transaction year, i.e YTD Funds Available includes actual activities
3768 -- accumulated during the current transaction year
3769 --
3770 -- For Budgets and Encumbrances, we do not need to include the begin
3771 -- balances of the first period since these are encumbrances, encumbered
3772 -- budgets and/or unused funds that are carried forward from the previous
3773 -- year
3774
3775 -- Subtraction of first period actual begin balance is done via special rows
3776 -- in gl_bc_period_map with boundary code 'S'. The PM.boundary_code AND
3777 -- clause in the correlated update query joins to these 'S' rows in addition
3778 -- to the regular PM rows for the case of YTD, and b/s or summary accounts,
3779 -- where they are eventually used in the 'AYTD' sum decode operation for the
3780 -- subtraction
3781 --
3782 -- Explain Plan :
3783 --
3784 -- OPERATION OPTIONS OBJECT_NAME
3785 -- ------------------------------------ ----------- -------------------
3786 -- SORT AGGREGATE
3787 -- NESTED LOOPS
3788 -- NESTED LOOPS
3789 -- TABLE ACCESS BY ROWID GL_BC_PACKETS
3790 -- INDEX RANGE SCAN GL_BC_PACKETS_N1
3791 -- INDEX RANGE SCAN GL_BC_PERIOD_MAP_U2
3792 -- TABLE ACCESS BY ROWID GL_BALANCES
3793 -- INDEX RANGE SCAN GL_BALANCES_N1
3794 --
3795
3796 -- Due to Bug 5644702 moved the fix of Bug 3243216 here.
3797
3798 BEGIN
3799 SELECT nvl(effective_period_num,0), period_name, NVL(quarter_num,0), NVL(period_year,0)
3800 INTO l_effective_period_num, l_period_name, l_quarter_num, l_period_year
3801 FROM gl_period_statuses
3802 WHERE ledger_id = g_ledger_id
3803 AND application_id = 101
3804 AND closing_status = 'O'
3805 AND effective_period_num =
3806 (SELECT max(effective_period_num)
3807 FROM gl_period_statuses
3808 WHERE ledger_id = g_ledger_id
3809 AND application_id = 101
3810 AND closing_status = 'O');
3811 EXCEPTION
3812 WHEN no_data_found THEN
3813 l_effective_period_num := 0;
3814 l_period_name := NULL;
3815 l_quarter_num := 0;
3816 l_period_year := 0;
3817 END;
3818 -- =========================== FND LOG ===========================
3819 psa_utils.debug_other_string(g_state_level,l_full_path,
3820 ' Picking up the lates OPEN period ' || SQL%ROWCOUNT );
3821 psa_utils.debug_other_string(g_state_level,l_full_path, ' l_effective_period_num -> ' || l_effective_period_num);
3822 psa_utils.debug_other_string(g_state_level,l_full_path, ' l_period_name -> ' || l_period_name);
3823 psa_utils.debug_other_string(g_state_level,l_full_path, ' l_quarter_num -> ' || l_quarter_num);
3824 psa_utils.debug_other_string(g_state_level,l_full_path, ' l_period_year -> ' || l_period_year);
3825 -- ========================= FND LOG =============================
3826
3827 -- Bugfix 2231059
3828
3829 update
3830 gl_bc_packets bp
3831 set (bp.budget_posted_balance,
3832 bp.actual_posted_balance,
3833 bp.encumbrance_posted_balance) =
3834 (
3835 select
3836
3837 sum(decode(gb.actual_flag || bp.amount_type, 'BPTD',
3838 nvl(gb.period_net_dr, 0) - nvl(gb.period_net_cr, 0),
3839 'BQTD', nvl(gb.quarter_to_date_dr, 0) -
3840 nvl(gb.quarter_to_date_cr, 0) +
3841 nvl(gb.period_net_dr, 0)- nvl(gb.period_net_cr, 0),
3842 'BYTD', nvl(gb.begin_balance_dr, 0) -
3843 nvl(gb.begin_balance_cr, 0) + nvl(gb.period_net_dr, 0) -
3844 nvl(gb.period_net_cr, 0),
3845 'BPJTD', nvl(gb.project_to_date_dr, 0) -
3846 nvl(gb.project_to_date_cr, 0) +
3847 nvl(gb.period_net_dr, 0) - nvl(gb.period_net_cr, 0), 0)),
3848 sum(decode(gb.actual_flag || bp.amount_type, 'APTD',
3849 nvl(gb.period_net_dr, 0) - nvl(gb.period_net_cr, 0),
3850 'AQTD', nvl(gb.quarter_to_date_dr, 0) -
3851 nvl(gb.quarter_to_date_cr, 0) +
3852 nvl(gb.period_net_dr, 0) - nvl(gb.period_net_cr, 0),
3853 'AYTD', decode(pm.boundary_code, 'S',
3854 nvl(gb.begin_balance_cr, 0) -
3855 nvl(gb.begin_balance_dr, 0),
3856 nvl(gb.begin_balance_dr, 0) -
3857 nvl(gb.begin_balance_cr, 0) + nvl(gb.period_net_dr, 0) -
3858 nvl(gb.period_net_cr, 0)),
3859 'APJTD', nvl(gb.project_to_date_dr, 0) -
3860 nvl(gb.project_to_date_cr, 0) +
3861 nvl(gb.period_net_dr, 0) - nvl(gb.period_net_cr, 0), 0)),
3862 sum(decode(gb.actual_flag || bp.amount_type, 'EPTD',
3863 nvl(gb.period_net_dr, 0) - nvl(gb.period_net_cr, 0),
3864 'EQTD', nvl(gb.quarter_to_date_dr, 0) -
3865 nvl(gb.quarter_to_date_cr, 0) +
3866 nvl(gb.period_net_dr, 0) - nvl(gb.period_net_cr, 0),
3867 'EYTD', nvl(gb.begin_balance_dr, 0) -
3868 nvl(gb.begin_balance_cr, 0) + nvl(gb.period_net_dr, 0) -
3869 nvl(gb.period_net_cr, 0),
3870 'EPJTD', nvl(gb.project_to_date_dr, 0) -
3871 nvl(gb.project_to_date_cr, 0) +
3872 nvl(gb.period_net_dr, 0) - nvl(gb.period_net_cr, 0), 0))
3873 from gl_bc_period_map pm,
3874 gl_balances gb
3875 -- ## selecting the latest open period
3876 -- ## Changes made For fix in Bug 3243216
3877 /* (select effective_period_num e, period_name n,quarter_num q,
3878 period_year y, ledger_id s, application_id a from gl_period_statuses
3879 where
3880 ledger_id= g_ledger_id and application_id =101 and closing_status='O'
3881 and effective_period_num =
3882 (select max(effective_period_num) from
3883 gl_period_statuses where ledger_id= g_ledger_id and application_id =101 and
3884 closing_status='O'))X*/ --Bug 5644702
3885 WHERE
3886 --- X.s = gb.ledger_id and x.a =101 and
3887 -- ## changes for the bug 3243216
3888 gb.ledger_id = g_ledger_id
3889 and gb.code_combination_id = bp.code_combination_id
3890 and gb.currency_code = g_func_curr_code
3891 and gb.actual_flag = pm.actual_flag
3892 and (gb.budget_version_id is null
3893 or gb.budget_version_id = pm.budget_version_id)
3894 -- ## Bug 3243216 replacement below
3895 AND GB.period_name = PM.query_period_name
3896 -- commented out below part as now we are selecting transaction period
3897 -- based on latest open period and accordingly joining with gl_balances on query_period
3898 /* AND GB.period_name = decode (PM.boundary_code, 'S', PM.query_period_name,
3899 decode(GB.actual_flag,
3900 'B', PM.query_period_name,
3901 'A', decode(GREATEST(BP.period_year*10000+BP.period_num, l_effective_period_num),
3902 BP.period_year*10000+BP.period_num,
3903 decode(BP.amount_type,
3904 'PTD', PM.query_period_Name,
3905 'QTD', decode(BP.period_year,
3906 l_period_year, decode(BP.quarter_num,
3907 l_quarter_num, l_period_name,
3908 pm.query_period_name),
3909 PM.query_period_name),
3910 'YTD', decode(BP.period_year,
3911 l_period_year, l_period_name,
3912 PM.query_Period_name),
3913 'PJTD',decode(l_period_name,
3914 NULL, PM.query_Period_name, l_period_name),
3915 PM.query_period_name),
3916 PM.query_period_name),
3917 'E', PM.query_period_name)
3918 ) */
3919
3920 and pm.ledger_id = g_ledger_id
3921 -- and pm.transaction_period_name = bp.period_name
3922 and pm.transaction_period_name = decode(pm.actual_flag,
3923 'B', bp.period_name,
3924 'A', decode(GREATEST(BP.period_year*10000+BP.period_num, l_effective_period_num),
3925 BP.period_year*10000+BP.period_num,
3926 decode(BP.amount_type,
3927 'PTD', bp.period_name,
3928 'QTD', decode(BP.period_year,
3929 l_period_year, decode(BP.quarter_num,
3930 l_quarter_num, l_period_name,
3931 bp.period_name),
3932 bp.period_name),
3933 'YTD', decode(BP.period_year,
3934 l_period_year, l_period_name,
3935 bp.period_name),
3936 'PJTD',decode(l_period_name,
3937 NULL, bp.period_name, l_period_name),
3938 bp.period_name),
3939 bp.period_name),
3940 'E', bp.period_name)
3941 and pm.boundary_code between 'A' AND 'Z'
3942 and pm.boundary_code || '' in
3943 (bp.boundary_code, decode(bp.amount_type, 'YTD',
3944 decode(bp.template_id, null, decode(bp.account_type,
3945 'A', 'S', 'L', 'S', 'O', 'S'), 'S')))
3946 and (pm.budget_version_id is null
3947 or pm.budget_version_id = bp.funding_budget_version_id)
3948 )
3949 where bp.packet_id = g_packet_id
3950 and bp.result_code is null
3951 and bp.effect_on_funds_code = 'D'
3952 and bp.funds_check_level_code <> 'N'
3953 and bp.currency_code = decode(bp.actual_flag, 'B', g_func_curr_code,
3954 bp.currency_code)
3955 and bp.funding_budget_version_id = decode(bp.actual_flag, 'B',
3956 bp.budget_version_id,
3957 bp.funding_budget_version_id);
3958
3959
3960 -- =========================== FND LOG ===========================
3961 psa_utils.debug_other_string(g_state_level,l_full_path,
3962 ' Update posted balance in gl_bc_packets ' || SQL%ROWCOUNT );
3963 -- ========================= FND LOG =============================
3964
3965 -- Commit to release Lock on gl_bc_dual
3966 -- commit; Commented for Bug 7476309
3967
3968
3969 -- Reestablish the Row Share Lock on gl_bc_dual2 to maintain data
3970 -- consistency between the Funds Checker Summarization and the Add/Delete
3971 -- Summary Accounts program
3972
3973 -- =========================== FND LOG ===========================
3974 -- psa_utils.debug_other_string(g_state_level,l_full_path,
3975 -- ' Lock table gl_bc_dual2 in row share mode nowait' ); --Commented for Bug 7476309
3976 -- ========================= FND LOG =============================
3977 -- LOCK TABLE gl_bc_dual2 IN ROW SHARE MODE NOWAIT; --Commented for Bug 7476309
3978
3979 -- =========================== FND LOG ===========================
3980 psa_utils.debug_other_string(g_state_level,l_full_path,' RETURN -> TRUE ' );
3981 -- ========================= FND LOG =============================
3982 return(TRUE);
3983
3984
3985 EXCEPTION
3986
3987 WHEN OTHERS THEN
3988
3989 -- =========================== FND LOG ===========================
3990 psa_utils.debug_other_string(g_excep_level,l_full_path,' EXCEPTION WHEN OTHERS '|| SQLERRM );
3991 -- ========================= FND LOG =============================
3992
3993 if SQLCODE = -54 then
3994 message_token('PROCEDURE', 'Funds Checker');
3995 message_token('EVENT', 'Table Locked by another Process');
3996 add_message('SQLGL', 'GL_UNHANDLED_EXCEPTION');
3997 else
3998 message_token('PROCEDURE', 'Funds Checker');
3999 message_token('EVENT', SQLERRM);
4000 add_message('SQLGL', 'GL_UNHANDLED_EXCEPTION');
4001 end if;
4002
4003 -- =========================== FND LOG ===========================
4004 psa_utils.debug_other_string(g_excep_level,l_full_path,' RETURN -> FALSE ' );
4005 -- ========================= FND LOG =============================
4006 g_debug := g_debug||' GLXFGB Failed : '||SQLERRM;
4007
4008 return(FALSE);
4009
4010 END glxfgb;
4011
4012 /* ================================ GLXFRC ============================ */
4013
4014 -- Update Result Codes
4015
4016 -- Set the Result Code for each transaction in the packet by computing funds
4017 -- availability
4018 --
4019 -- In case of Overrides, update the result codes for the detail transactions,
4020 -- generated transactions and summary transactions if the Transaction Amount
4021 -- is less than or equal to the Override Amount
4022 --
4023 -- Update the Result Code for each detail transaction that causes one or
4024 -- more of its corresponding summary transactions to fail Funds Check or
4025 -- Funds Reservation
4026 --
4027 -- Update the Result Code for each detail transaction that has one or more
4028 -- of its associated proprietary or Budgetary transactions that fail
4029 -- Funds Check or Funds Reservation (only when USSGL Option is set)
4030
4031 -- Structure of the Result Codes :
4032 --
4033 -- Range Meaning
4034 -- -------- ------------------------------------------------------------
4035 -- P00 - P09 Pass; Does not reduce FA / Does not require FC
4036 -- P10 - P14 Pass; Normal Pass - Proprietary
4037 -- P15 - P19 Pass; Normal Pass - Budgetary
4038 -- P20 - P24 Pass; Pass with Warnings - Proprietary
4039 -- P25 - P29 Pass; Pass with Warnings - Budgetary
4040 -- F00 - F09 Fail; Insufficient Funds - Proprietary
4041 -- F10 - F19 Fail; Insufficient Funds - Budgetary
4042 -- F20 - F29 Fail; Validation Errors
4043
4044 -- Result Codes for Funds Reservation/Check :
4045 --
4046 -- Code Explanation
4047 -- ---- --------------------------------------------------------
4048 -- P00 This transaction does not reduce Funds available
4049 -- P01 This account does not require Funds Check
4050 -- P02 This budget transaction applies to a budget other than your
4051 -- Funding Budget
4052 -- P03 This foreign currency budget transaction does not
4053 -- require Funds Check
4054 -- P04 This summary transaction is created by the Add Summary Accounts
4055 -- program
4056 -- P05 This transaction passes Funds Check in Force Pass mode
4057 -- P10 This transaction passes Funds Check
4058 -- P15 This budgetary transaction passes Funds Check
4059 -- P20 This transaction fails Funds Check; advisory checking is in
4060 -- force
4061 -- P21 This transaction fails Funds Check; you overrode the failure
4062 -- P22 This detail transaction causes a summary account to fail
4063 -- Funds Check (advisory)
4064 -- P23 This summary account fails Funds Check; you overrode
4065 -- the detail(s)
4066 -- P25 This budgetary transaction fails Funds Check; advisory checking
4067 -- is in force
4068 -- P26 This budgetary transaction fails Funds Check; you overrode the
4069 -- failure
4070 -- P27 This budgetary transaction causes a summary account to fail
4071 -- to fail Funds Check (advisory)
4072 -- F00 This detail transaction fails Funds Check
4073 -- F01 This detail transaction causes a summary account to fail
4074 -- Funds Check
4075 -- F02 This summary account fails Funds Check
4076 -- F03 One or more earlier pending transactions cause this
4077 -- transaction to fail
4078 -- F04 This detail transaction fails and causes a summary account to
4079 -- fail Funds Check
4080 -- F05 One or more associated generated transactions cause this
4081 -- transaction to fail
4082 -- F06 One or more associated transactions cause this proprietary
4083 -- transaction to fail
4084 -- F10 This budgetary detail transaction fails Funds Check
4085 -- F11 This budgetary detail transaction causes a summary account to
4086 -- fail Funds Check
4087 -- F12 This budgetary summary account fails Funds Check
4088 -- F13 One or more earlier pending transactions cause the budgetary
4089 -- transaction to fail
4090 -- F14 This budgetary transaction fails and also causes a summary
4091 -- account to fail
4092 -- F15 One or more associated transactions cause this budgetary
4093 -- transaction to fail
4094 -- F20 This Accounting Flexfield does not exist
4095 -- F21 This Accounting Flexfield is disabled or out-of-date
4096 -- F22 This Accounting Flexfield does not allow detail posting
4097 -- F23 This Accounting Flexfield does not allow detail budget posting
4098 -- F24 This accounting period does not exist
4099 -- F25 This accounting period is neither Open nor Future Enterable
4100 -- F26 This accounting period is not within an open budget year
4101 -- F27 This budget is frozen
4102 -- F28 This USSGL transaction code is out-of-date
4103
4104 FUNCTION glxfrc RETURN BOOLEAN IS
4105
4106 cursor retcode is
4107 select decode(count(*),
4108 count(decode(substr(bp.result_code, 1, 1), 'P', 1)),
4109 decode(sign(count(decode(bp.result_code, 'P20', 1,
4110 'P22', 1,
4111 'P25', 1,
4112 'P27', 1,
4113 'P31', 1,
4114 'P35', 1,
4115 'P36', 1,
4116 'P37', 1,
4117 'P38', 1,
4118 'P39', 1))), 0, 'S', 1, 'A'),
4119 count(decode(substr(bp.result_code, 1, 1), 'F', 1)),
4120 'F', decode(g_partial_resv_flag, 'Y', 'P', 'F'))
4121 from gl_bc_packets bp
4122 where bp.packet_id = g_packet_id
4123 and bp.template_id is null;
4124
4125 l_ret_code gl_bc_packets.result_code%type;
4126
4127 -- Bug 5571064 .. Start
4128
4129 CURSOR c_get_failed_distributions(p_packet_id IN NUMBER) IS
4130 SELECT distinct bc.source_distribution_id_num_1
4131 FROM gl_bc_packets bc
4132 WHERE bc.packet_id = p_packet_id
4133 AND bc.result_code like 'F%';
4134
4135 TYPE source_dist_id_num_1_tbl_type IS TABLE OF gl_bc_packets.source_distribution_id_num_1%type INDEX BY binary_integer;
4136
4137 l_source_dist_id_num_1_tbl source_dist_id_num_1_tbl_type;
4138
4139 -- Bug 5571064 .. End
4140
4141 -- ========================= FND LOG ===========================
4142 l_full_path VARCHAR2(100);
4143 -- ========================= FND LOG ===========================
4144
4145 BEGIN
4146
4147 l_full_path := g_path || 'glxfrc';
4148
4149 -- =========================== FND LOG ===========================
4150 psa_utils.debug_other_string(g_state_level,l_full_path, ' GLXFRC - START' );
4151 -- ========================= FND LOG =============================
4152
4153 -- Update Result Code for all transactions in Packet
4154 update gl_bc_packets bp
4155 set bp.result_code =
4156 decode(bp.actual_flag || decode(bp.currency_code, g_func_curr_code,
4157 null, '1'), 'B1', 'P03',
4158 decode(bp.actual_flag || decode(bp.budget_version_id,
4159 bp.funding_budget_version_id, null, '1'), 'B1', 'P02',
4160 decode(bp.funds_check_level_code, 'N', 'P01',
4161 decode(bp.effect_on_funds_code, 'I', 'P00',
4162 decode(g_fcmode, 'F', 'P05', decode(bp.account_category_code,
4163 'P',
4164 decode(sign(
4165 ((nvl(bp.budget_posted_balance, 0) -
4166 nvl(bp.actual_posted_balance, 0) -
4167 nvl(bp.encumbrance_posted_balance, 0) +
4168 nvl(bp.budget_approved_balance, 0) -
4169 nvl(bp.actual_approved_balance, 0) -
4170 nvl(bp.encumbrance_approved_balance, 0) +
4171 nvl(bp.budget_pending_balance, 0) -
4172 nvl(bp.actual_pending_balance, 0) -
4173 nvl(bp.encumbrance_pending_balance, 0)) -
4174 ((nvl(bp.accounted_dr, 0) -
4175 nvl(bp.accounted_cr, 0)) *
4176 decode(bp.actual_flag, 'B', -1, 1)) +
4177 decode(sign(
4178 (nvl(bp.budget_posted_balance, 0) +
4179 nvl(bp.budget_approved_balance, 0) +
4180 nvl(bp.budget_pending_balance, 0)) *
4181 decode(bp.dr_cr_code, 'D', 1, -1)),
4182 -1, nvl(bp.tolerance_amount, 0),
4183 decode(bp.tolerance_percentage ||
4184 ';' || bp.tolerance_amount, ';', 0,
4185 ';' || bp.tolerance_amount,
4186 bp.tolerance_amount,
4187 bp.tolerance_percentage || ';',
4188 abs(nvl(bp.budget_posted_balance, 0) +
4189 nvl(bp.budget_approved_balance, 0) +
4190 nvl(bp.budget_pending_balance, 0)) *
4191 bp.tolerance_percentage/100,
4192 least(
4193 abs(nvl(bp.budget_posted_balance, 0) +
4194 nvl(bp.budget_approved_balance, 0) +
4195 nvl(bp.budget_pending_balance, 0)) *
4196 bp.tolerance_percentage/100,
4197 bp.tolerance_amount))) *
4198 decode(bp.dr_cr_code, 'D', 1, -1)) *
4199 decode(bp.dr_cr_code, 'D', 1, -1)), 1, 'P10',
4200 0, 'P10', decode(bp.funds_check_level_code,
4201 'D', 'P20',
4202 decode(sign(nvl(bp.template_id,
4203 -1)), 1, 'F02',
4204 decode(sign(
4205 ((nvl(bp.budget_posted_balance, 0) -
4206 nvl(bp.actual_posted_balance, 0) -
4207 nvl(bp.encumbrance_posted_balance, 0) +
4208 nvl(bp.budget_approved_balance, 0) -
4209 nvl(bp.actual_approved_balance, 0) -
4210 nvl(bp.encumbrance_approved_balance, 0)) -
4211 ((nvl(bp.accounted_dr, 0) -
4212 nvl(bp.accounted_cr, 0)) *
4213 decode(bp.actual_flag, 'B', -1, 1)) +
4214 decode(sign(
4215 (nvl(bp.budget_posted_balance, 0) +
4216 nvl(bp.budget_approved_balance, 0) +
4217 nvl(bp.budget_pending_balance, 0)) *
4218 decode(bp.dr_cr_code, 'D', 1, -1)),
4219 -1, nvl(bp.tolerance_amount, 0),
4220 decode(bp.tolerance_percentage || ';' ||
4221 bp.tolerance_amount, ';', 0,
4222 ';' || bp.tolerance_amount,
4223 bp.tolerance_amount,
4224 bp.tolerance_percentage || ';',
4225 abs(nvl(bp.budget_posted_balance, 0) +
4226 nvl(bp.budget_approved_balance, 0) +
4227 nvl(bp.budget_pending_balance, 0)) *
4228 bp.tolerance_percentage/100,
4229 least(
4230 abs(nvl(bp.budget_posted_balance, 0) +
4231 nvl(bp.budget_approved_balance, 0) +
4232 nvl(bp.budget_pending_balance, 0)) *
4233 bp.tolerance_percentage/100,
4234 bp.tolerance_amount))) *
4235 decode(bp.dr_cr_code, 'D', 1, -1)) *
4236 decode(bp.dr_cr_code, 'D', 1, -1)),
4237 -1, 'F00', 'F03')))),
4238 'B',
4239 decode(sign(
4240 ((nvl(bp.actual_posted_balance, 0) +
4241 nvl(bp.actual_approved_balance, 0) +
4242 nvl(bp.actual_pending_balance, 0)) -
4243 ((nvl(bp.accounted_cr, 0) -
4244 nvl(bp.accounted_dr, 0)))) *
4245 decode(bp.dr_cr_code, 'D', 1, -1)), 1, 'P15',
4246 0, 'P15',
4247 decode(bp.funds_check_level_code, 'D', 'P25',
4248 decode(sign(nvl(bp.template_id, -1)),
4249 1, 'F12',
4250 decode(sign(
4251 ((nvl(bp.actual_posted_balance, 0) +
4252 nvl(bp.actual_approved_balance, 0)) -
4253 ((nvl(bp.accounted_cr, 0) -
4254 nvl(bp.accounted_dr, 0)))) *
4255 decode(bp.dr_cr_code, 'D', 1, -1)),
4256 -1, 'F10', 'F13'))))))))))
4257 where bp.packet_id = g_packet_id
4258 and (bp.result_code is null
4259 or g_fcmode = 'F' );
4260
4261
4262
4263 -- =========================== FND LOG ===========================
4264 psa_utils.debug_other_string(g_state_level,l_full_path, ' Update Result Code gl_bc_packets 1 updated -> ' || SQL%ROWCOUNT || ' rows');
4265 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_fcmode -> ' || g_fcmode);
4266 -- ========================= FND LOG =============================
4267
4268 /* -------------------------------------------------------------------+
4269 | Updating result code to F78 id funds check is failed and absolute|
4270 | Funds checking is done when there were no Budget Assignment |
4271 | Bug 5242198 |
4272 +-----------------------------------------------------------------*/
4273
4274 if(nvl(g_enable_efc_flag,'N')='Y') THEN
4275
4276 UPDATE gl_bc_packets bp
4277 set result_code='F78'
4278 WHERE bp.packet_id = g_packet_id
4279 AND bp.result_code like 'F%'
4280 AND bp.funding_budget_version_id IS NULL
4281 AND bp.funds_check_level_code = 'B';
4282
4283 end if;
4284 -- If Mode is Force Pass, there is no need for detail/summary and
4285 -- originating/generated tie back logic
4286
4287 if g_fcmode = 'F' then
4288 -- =========================== FND LOG ===========================
4289 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_fcmode = F -> goto normal_exit');
4290 -- ========================= FND LOG =============================
4291 goto normal_exit;
4292 end if;
4293
4294
4295 if g_summarized_flag then
4296
4297 -- =========================== FND LOG ===========================
4298 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_summarized_flag -> TRUE ');
4299 -- ========================= FND LOG =============================
4300
4301 -- Update Result Code for Detail Transactions when Summary Transactions
4302 -- fail Funds Check and Checking is Absolute
4303
4304 update gl_bc_packets bp
4305 set bp.result_code =
4306 decode(bp.account_category_code || substr(bp.result_code, 1, 1),
4307 'PP', 'F01', 'PF', 'F04', 'BP', 'F11', 'BF', 'F14')
4308 where bp.packet_id = g_packet_id
4309 and bp.template_id is null
4310 and (bp.result_code like 'P%'
4311 or bp.result_code in ('F00', 'F03', 'F10', 'F13'))
4312 and exists
4313 (
4314 select
4315
4316 'Summary Row exists and fails Funds Check; Absolute'
4317 from gl_bc_packets pk,
4318 gl_account_hierarchies ah
4319 where ah.ledger_id = bp.ledger_id
4320 and ah.summary_code_combination_id = pk.code_combination_id
4321 and ah.detail_code_combination_id = bp.code_combination_id
4322 and pk.packet_id = bp.packet_id
4323 and pk.actual_flag = bp.actual_flag
4324 and pk.period_name = bp.period_name
4325 and pk.je_source_name = bp.je_source_name
4326 and pk.je_category_name = bp.je_category_name
4327 and (pk.budget_version_id is null
4328 or pk.budget_version_id = bp.budget_version_id)
4329 and pk.account_category_code = bp.account_category_code
4330 and pk.funds_check_level_code = 'B'
4331 and pk.result_code in ('F02', 'F12')
4332 );
4333
4334 -- =========================== FND LOG ===========================
4335 psa_utils.debug_other_string(g_state_level,l_full_path, ' update gl_bc_packets 2 updated -> ' || SQL%ROWCOUNT || ' rows');
4336 -- ========================= FND LOG =============================
4337
4338 -- Update Result Code for Detail Transactions when Summary Transactions
4339 -- fail Funds Check and Checking is Advisory
4340
4341 update gl_bc_packets bp
4342 set bp.result_code =
4343 decode(bp.account_category_code, 'P', 'P22', 'B', 'P27')
4344 where bp.packet_id = g_packet_id
4345 and bp.template_id is null
4346 and bp.result_code like 'P%'
4347 and exists
4348 (
4349 select
4350
4351 'Summary Row exists and fails Funds Check; Advisory'
4352 from gl_account_hierarchies ah,
4353 gl_bc_packets pk
4354 where ah.ledger_id = bp.ledger_id
4355 and ah.summary_code_combination_id = pk.code_combination_id
4356 and ah.detail_code_combination_id = bp.code_combination_id
4357 and pk.packet_id = bp.packet_id
4358 and pk.actual_flag = bp.actual_flag
4359 and pk.period_name = bp.period_name
4360 and pk.je_source_name = bp.je_source_name
4361 and pk.je_category_name = bp.je_category_name
4362 and (pk.budget_version_id is null
4363 or pk.budget_version_id = bp.budget_version_id)
4364 and pk.account_category_code = bp.account_category_code
4365 and pk.funds_check_level_code = 'D'
4366 and pk.result_code in ('P20', 'P25')
4367 );
4368
4369 -- =========================== FND LOG ===========================
4370 psa_utils.debug_other_string(g_state_level,l_full_path, ' update gl_bc_packets 3 updated -> ' || SQL%ROWCOUNT || ' rows');
4371 -- ========================= FND LOG =============================
4372
4373 end if;
4374
4375
4376 -- Update Result Code of Original Proprietary Transaction when one or
4377 -- more of the associated Generated Transactions fail Funds Check and
4378 -- vice versa
4379
4380 if g_ussgl_option_flag then
4381
4382 -- =========================== FND LOG ===========================
4383 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_ussgl_option_flag -> TRUE');
4384 -- ========================= FND LOG =============================
4385
4386 update gl_bc_packets bp
4387 set bp.result_code =
4388 decode(bp.ussgl_transaction_code, null,
4389 decode(bp.account_category_code, 'P', 'F06', 'B', 'F15'),
4390 'F05')
4391 where bp.packet_id = g_packet_id
4392 and bp.template_id is null
4393 and bp.result_code like 'P%'
4394 and (bp.ussgl_transaction_code is not null
4395 or bp.ussgl_link_to_parent_id is not null)
4396 and exists
4397 (
4398 select 'One or more Proprietary/Budgetary counterparts of ' ||
4399 'this transaction exists and fails Funds Check'
4400 from gl_bc_packets pk
4401 where pk.packet_id = g_packet_id
4402 and pk.template_id is null
4403 and pk.result_code like 'F%'
4404 and (pk.ussgl_parent_id = bp.ussgl_link_to_parent_id
4405 or pk.ussgl_link_to_parent_id in (bp.ussgl_link_to_parent_id, bp.ussgl_parent_id))
4406 );
4407
4408 -- =========================== FND LOG ===========================
4409 psa_utils.debug_other_string(g_state_level,l_full_path, ' update gl_bc_packets 4 updated -> ' || SQL%ROWCOUNT || ' rows');
4410 -- ========================= FND LOG =============================
4411
4412 end if;
4413
4414 -- New logic added here for sub-ledger teams to populate full set of
4415 -- result codes. This is applicable to GL only if called from a
4416 -- concurrent program because in case of concurrent program the override
4417 -- functionality will be disabled even for GL.
4418
4419 IF g_calling_prog_flag = 'S' OR g_conc_flag THEN
4420
4421 IF g_override_flag THEN
4422
4423 if not glxfor then
4424 -- =========================== FND LOG ===========================
4425 psa_utils.debug_other_string(g_state_level,l_full_path, ' glxfor --> RETURN FALSE -> goto fatal_error');
4426 -- ========================= FND LOG =============================
4427 return false;
4428 end if;
4429 END IF;
4430
4431 open retcode;
4432 fetch retcode into l_ret_code;
4433 close retcode;
4434
4435 if ((g_fcmode in ('R', 'U', 'A')) and
4436 (g_summarized_flag) and
4437 (l_ret_code in ('S', 'A'))) then
4438
4439 -- ========================= FND LOG ===========================
4440 psa_utils.debug_other_string(g_state_level,l_full_path, ' inside Ist IF ');
4441 -- ========================= FND LOG ===========================
4442
4443 update gl_bc_packets bp
4444 set bp.result_code = 'P23'
4445 where bp.packet_id = g_packet_id
4446 and bp.result_code like 'F%'
4447 and bp.template_id is not null;
4448
4449 -- ========================= FND LOG ===========================
4450 psa_utils.debug_other_string(g_state_level,l_full_path, ' update gl_bc_packets 5 updated -> ' || SQL%ROWCOUNT || ' rows');
4451 -- ========================= FND LOG ===========================
4452
4453 end if;
4454
4455 update gl_bc_packets bp
4456 set bp.status_code = decode(bp.status_code || l_ret_code,
4457 'PF', 'R',
4458 'CF', 'F',
4459 decode(bp.status_code || substr(bp.result_code, 1, 1),
4460 'PF', 'R',
4461 'CF', 'F',
4462 bp.status_code)
4463 ),
4464 bp.last_update_date = sysdate
4465 where bp.packet_id = g_packet_id;
4466
4467 -- ========================= FND LOG ===========================
4468 psa_utils.debug_other_string(g_state_level,l_full_path, ' update gl_bc_packets 6 updated -> ' || SQL%ROWCOUNT || ' rows');
4469 -- ========================= FND LOG ===========================
4470
4471 END IF;
4472
4473 -- Update all lines to failure in same packet and same distribution if any other line fails.
4474 -- Bug 5250753
4475 -- Bug 5571064
4476
4477 OPEN c_get_failed_distributions (g_packet_id);
4478 FETCH c_get_failed_distributions bulk collect into l_source_dist_id_num_1_tbl;
4479
4480 FORALL I IN 1..l_source_dist_id_num_1_tbl.count
4481 UPDATE gl_bc_packets pk
4482 SET result_code ='F77'
4483 WHERE pk.packet_id = g_packet_id
4484 AND pk.source_distribution_id_num_1 = l_source_dist_id_num_1_tbl(I)
4485 AND pk.result_code like 'P%';
4486
4487 -- ========================= FND LOG ===========================
4488 psa_utils.debug_other_string(g_state_level,l_full_path,
4489 ' update gl_bc_packets 6.1, result_code to F77 for same packet and same distribution updated -> ' || SQL%ROWCOUNT || ' rows');
4490 -- ========================= FND LOG ===========================
4491
4492 CLOSE c_get_failed_distributions;
4493
4494 -- Bug 3553142
4495 -- If there is an advisory warning on any row in gl_bc_packets, all passed rows should indicate
4496 -- that one or more related lines have advisory warnings.
4497 -- Created 2 new LOOKUP_CODEs P12, P17
4498
4499 UPDATE gl_bc_packets pk
4500 SET result_code = 'P12'
4501 WHERE pk.packet_id = g_packet_id
4502 AND result_code = 'P10'
4503 AND exists (SELECT 'x'
4504 FROM gl_bc_packets bc
4505 WHERE bc.packet_id = pk.packet_id
4506 AND bc.result_code = 'P20');
4507
4508 -- ========================= FND LOG ===========================
4509 psa_utils.debug_other_string(g_state_level,l_full_path, ' update gl_bc_packets 7 updated -> ' || SQL%ROWCOUNT || ' rows');
4510 -- ========================= FND LOG ===========================
4511
4512
4513 UPDATE gl_bc_packets pk
4514 SET result_code = 'P17'
4515 WHERE pk.packet_id = g_packet_id
4516 AND result_code = 'P15'
4517 AND exists (SELECT 'x'
4518 FROM gl_bc_packets bc
4519 WHERE bc.packet_id = pk.packet_id
4520 AND bc.result_code = 'P25');
4521
4522 -- ========================= FND LOG ===========================
4523 psa_utils.debug_other_string(g_state_level,l_full_path, ' update gl_bc_packets 8 updated -> ' || SQL%ROWCOUNT || ' rows');
4524 -- ========================= FND LOG ===========================
4525
4526
4527 -- =========================== FND LOG ===========================
4528 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN -> TRUE');
4529 -- ========================= FND LOG =============================
4530
4531 return(TRUE);
4532
4533 <<normal_exit>>
4534 -- =========================== FND LOG ===========================
4535 psa_utils.debug_other_string(g_state_level,l_full_path, ' Reached label normal exit');
4536 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN -> TRUE');
4537 -- ========================= FND LOG =============================
4538
4539 return(TRUE);
4540
4541 EXCEPTION
4542
4543 WHEN OTHERS THEN
4544 -- =========================== FND LOG ===========================
4545 psa_utils.debug_other_string(g_excep_level,l_full_path, ' EXCEPTION WHEN OTHERS ' || SQLERRM);
4546 -- ========================= FND LOG =============================
4547
4548 message_token('PROCEDURE', 'Funds Checker');
4549 message_token('EVENT', SQLERRM);
4550 add_message('SQLGL', 'GL_UNHANDLED_EXCEPTION');
4551
4552 -- =========================== FND LOG ===========================
4553 psa_utils.debug_other_string(g_excep_level,l_full_path, ' RETURN -> FALSE');
4554 -- ========================= FND LOG =============================
4555 g_debug := g_debug||' GLXFRC Failed : '||SQLERRM;
4556 return(FALSE);
4557
4558 END glxfrc;
4559
4560 /* ============================= GLZCBC =============================== */
4561
4562 FUNCTION glzcbc RETURN NUMBER IS
4563
4564 cbc_fck_stmt VARCHAR2(2000);
4565 p_ledger_id NUMBER(15);
4566 p_packet_id NUMBER(15);
4567 p_conc_proc VARCHAR2(1);
4568 p_mode VARCHAR2(1);
4569 cbc_code NUMBER(15);
4570
4571 -- ========================= FND LOG ===========================
4572 l_full_path VARCHAR2(100);
4573 -- ========================= FND LOG ===========================
4574 BEGIN
4575
4576 p_conc_proc := 'F';
4577 l_full_path := g_path || 'glzcbc.';
4578
4579 -- =========================== FND LOG ===========================
4580 psa_utils.debug_other_string(g_state_level,l_full_path, ' GLZCBC - START' );
4581 -- ========================= FND LOG =============================
4582
4583 cbc_fck_stmt :=
4584 'BEGIN :ret_code := IGC_CBC_GL_FC_PKG.glzcbc(:packet_id,p_ledger_id,:mode,:conc_proc); END;';
4585
4586 -- =========================== FND LOG ===========================
4587 psa_utils.debug_other_string(g_state_level,l_full_path, ' cbc_fck_stmt -> ' || cbc_fck_stmt );
4588 -- ========================= FND LOG =============================
4589
4590 -- Assign parameter values before calling IGC
4591
4592 p_ledger_id := g_ledger_id;
4593 p_packet_id := g_packet_id;
4594 p_mode := g_fcmode;
4595
4596 -- =========================== FND LOG ===========================
4597 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_ledger_id -> ' || g_ledger_id );
4598 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_packet_id -> ' || g_packet_id );
4599 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_fcmode -> ' || g_fcmode );
4600 -- ========================= FND LOG =============================
4601
4602 execute immediate cbc_fck_stmt
4603 USING IN OUT cbc_code,IN p_packet_id,IN p_ledger_id,IN p_mode,IN p_conc_proc;
4604
4605 -- =========================== FND LOG ===========================
4606 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN cbc_code -> ' || cbc_code );
4607 -- ========================= FND LOG =============================
4608
4609 RETURN cbc_code;
4610
4611 EXCEPTION
4612 WHEN OTHERS THEN
4613
4614 -- =========================== FND LOG ===========================
4615 psa_utils.debug_other_string(g_excep_level,l_full_path, ' RETURN -> 1' );
4616 -- ========================= FND LOG =============================
4617
4618 RETURN 1;
4619
4620 END glzcbc;
4621
4622 /* ================================ GLZGCHK ========================== */
4623
4624 -- Callout to Grants Funds Check extension. The resulting Return Code
4625 -- is returned back through an out parameter. Any error in processing
4626 -- results in a return value from the function of FALSE.
4627
4628 FUNCTION glzgchk RETURN BOOLEAN IS
4629
4630 gms_stmt VARCHAR2(400);
4631
4632 -- ========================= FND LOG ===========================
4633 l_full_path VARCHAR2(100);
4634 -- ========================= FND LOG ===========================
4635
4636 BEGIN
4637
4638 l_full_path := g_path || 'glzgchk';
4639
4640 -- =========================== FND LOG ===========================
4641 psa_utils.debug_other_string(g_state_level,l_full_path, ' GLZGCHK - START' );
4642 -- ========================= FND LOG =============================
4643
4644 gms_stmt :=
4645 'BEGIN '||
4646 ' GMS_UTILITY.GMS_UTIL_PC_FCK('||
4647 ':g_ledger_id, :g_packet_id, :g_fcmode, '||
4648 '''N'', :g_partial_resv_flag, '||
4649 'FND_GLOBAL.USER_ID, FND_GLOBAL.RESP_ID, '||
4650 '''N'', :gms_retcode); '||
4651 'END;';
4652
4653 -- =========================== FND LOG ===========================
4654 psa_utils.debug_other_string(g_state_level,l_full_path, ' gms_stmt -> ' || gms_stmt );
4655 -- ========================= FND LOG =============================
4656
4657 execute immediate gms_stmt using g_ledger_id, g_packet_id, g_fcmode,
4658 g_partial_resv_flag, in out gms_retcode;
4659
4660 -- =========================== FND LOG ===========================
4661 psa_utils.debug_other_string(g_state_level,l_full_path, ' gms_retcode -> ' || gms_retcode );
4662 -- ========================= FND LOG =============================
4663
4664 IF NOT gms_retcode = '~'
4665 AND gms_retcode IS NOT NULL THEN
4666 -- =========================== FND LOG ===========================
4667 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN -> TRUE' );
4668 -- ========================= FND LOG =============================
4669 RETURN(TRUE);
4670 END IF;
4671
4672 -- =========================== FND LOG ===========================
4673 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN -> FALSE' );
4674 -- ========================= FND LOG =============================
4675 RETURN(FALSE);
4676
4677 EXCEPTION
4678
4679 WHEN OTHERS THEN
4680
4681 -- =========================== FND LOG ===========================
4682 psa_utils.debug_other_string(g_excep_level,l_full_path, ' EXCEPTION WHEN OTHER '|| SQLERRM );
4683 -- ========================= FND LOG =============================
4684
4685 /* Even when an SQL exception is raised, if the gms_retcode */
4686 /* has been set, indicate that processing has completed. */
4687 /* This ensures that any cleanup that needs to be done by */
4688 /* the GMS_RETURN_CODE processor is at least attempted. */
4689
4690 IF NOT gms_retcode = '~'
4691 AND gms_retcode IS NOT NULL THEN
4692 -- =========================== FND LOG ===========================
4693 psa_utils.debug_other_string(g_excep_level,l_full_path, ' RETURN -> TRUE' );
4694 -- ========================= FND LOG =============================
4695 RETURN(TRUE);
4696 ELSE
4697 -- =========================== FND LOG ===========================
4698 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN -> FALSE' );
4699 -- ========================= FND LOG =============================
4700 RETURN(FALSE);
4701 END IF;
4702
4703 END glzgchk;
4704
4705 /* ================================ GLZPAFCK =========================== */
4706
4707 -- Callout to Projects Funds Check extension. The resulting Return Code
4708 -- is returned back through an out parameter. Any error in processing
4709 -- results in a return value from the function of FALSE.
4710
4711 FUNCTION glzpafck RETURN BOOLEAN IS
4712
4713 pa_stmt VARCHAR2(400);
4714 cur_pa INTEGER;
4715 ignore INTEGER;
4716
4717 pa_retcode gl_bc_packets.result_code%TYPE;
4718 err_msg VARCHAR2(1024);
4719 err_stg VARCHAR2(1024);
4720
4721 -- ========================= FND LOG ===========================
4722 l_full_path VARCHAR2(100);
4723 -- ========================= FND LOG ===========================
4724 BEGIN
4725
4726 l_full_path := g_path || 'glzpafck.';
4727
4728 -- ========================= FND LOG ===========================
4729 psa_utils.debug_other_string(g_state_level,l_full_path, ' GLZPAFCK --> START ');
4730 -- ========================= FND LOG ===========================
4731
4732 pa_stmt :=
4733 'BEGIN '||
4734 ' PA_FUNDS_CONTROL_PKG.PA_FUNDS_CHECK(:gl_var, :g_ledger_id_var, :g_packet_id_var, '||
4735 ':g_fcmode_var, :g_partial_resv_flag_var, NULL, NULL,:pa_retcode, :err_msg, :err_stg); '||
4736 'END;';
4737
4738 -- ========================= FND LOG ===========================
4739 psa_utils.debug_other_string(g_state_level,l_full_path, ' pa_stmt -> ' || pa_stmt);
4740 -- ========================= FND LOG ===========================
4741
4742 EXECUTE IMMEDIATE pa_stmt USING 'GL', g_ledger_id, g_packet_id, g_fcmode,
4743 g_partial_resv_flag, OUT pa_retcode,
4744 OUT err_msg, OUT err_stg;
4745
4746 IF err_msg IS NOT NULL THEN
4747 -- ========================= FND LOG ===========================
4748 psa_utils.debug_other_string(g_state_level,l_full_path, ' pa_retcode -> ' || pa_retcode);
4749 psa_utils.debug_other_string(g_state_level,l_full_path, ' err_msg -> ' || err_msg);
4750 psa_utils.debug_other_string(g_state_level,l_full_path, ' err_stg -> ' || err_stg);
4751 -- ========================= FND LOG ===========================
4752 END IF;
4753
4754 IF (pa_retcode IS NULL) OR (pa_retcode = 'T') THEN
4755 -- ========================= FND LOG ===========================
4756 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN -> FALSE ');
4757 -- ========================= FND LOG ===========================
4758 g_debug := g_debug||' GLZPAFCK Failed : (PA_RETCODE IS NULL OR PA_RETCODE = T)';
4759 RETURN(FALSE);
4760 END IF;
4761
4762 -- ========================= FND LOG ===========================
4763 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN -> TRUE ');
4764 -- ========================= FND LOG ===========================
4765
4766 RETURN(TRUE);
4767
4768 EXCEPTION
4769
4770 WHEN OTHERS THEN
4771 -- ========================= FND LOG ===========================
4772 psa_utils.debug_other_string(g_excep_level,l_full_path, ' EXCEPTION WHEN OTHERS ');
4773 -- ========================= FND LOG ===========================
4774
4775 /* Even when an SQL exception is raised, if the pa_retcode */
4776 /* has been set, indicate that processing has completed. */
4777
4778 IF pa_retcode = 'T' THEN
4779 -- ========================= FND LOG ===========================
4780 psa_utils.debug_other_string(g_excep_level,l_full_path, ' RETURN -> FALSE ');
4781 -- ========================= FND LOG ===========================
4782 g_debug := g_debug||' GLZPAFCK Failed : PA_RETCODE = T';
4783 RETURN(FALSE);
4784 END IF;
4785
4786 -- ========================= FND LOG ===========================
4787 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN -> TRUE ');
4788 -- ========================= FND LOG ===========================
4789
4790 RETURN(TRUE);
4791
4792 END glzpafck;
4793
4794 /* =========================== GLXFOR =================================== */
4795
4796 -- Update the Result Codes for all Detail Transactions to 'P21' and the
4797 -- corresponding Generated Transactions to 'P26', if the Transaction Amount
4798 -- is less than or equal to the Override Amount for the Detail Transaction;
4799 -- Result Codes for Summary Transactions are updated in glxfrs()
4800
4801 FUNCTION glxfor RETURN BOOLEAN IS
4802 -- ========================= FND LOG ===========================
4803 l_full_path VARCHAR2(100);
4804 -- ========================= FND LOG ===========================
4805 BEGIN
4806
4807 l_full_path := g_path || 'glxfor';
4808
4809 -- ========================= FND LOG ===========================
4810 psa_utils.debug_other_string(g_state_level, l_full_path, ' GLXFOR --> START ');
4811 -- ========================= FND LOG ===========================
4812
4813 -- Update Result Code for Detail Transactions
4814
4815 update gl_bc_packets bp
4816 set bp.result_code = 'P21'
4817 where bp.packet_id = g_packet_id
4818 and bp.result_code between 'F00' and 'F19'
4819 and bp.ussgl_link_to_parent_id is null
4820 and bp.template_id is null
4821 and nvl(bp.override_amount, -1) >=
4822 abs(nvl(bp.accounted_dr, 0) - nvl(bp.accounted_cr, 0))
4823 and not exists
4824 (
4825 select 'If Partial Resv disallowed then all non-generated ' ||
4826 'detail lines that failed with any validation errors ' ||
4827 'or because of Funds Availability'
4828 from gl_bc_packets pk
4829 where pk.packet_id = g_packet_id
4830 and pk.template_id is null
4831 and pk.result_code like 'F%'
4832 and ((g_partial_resv_flag = 'N'
4833 and pk.ussgl_link_to_parent_id is null
4834 and (pk.result_code between 'F20' and 'F29'
4835 or nvl(pk.override_amount, -1) <
4836 abs(nvl(pk.accounted_dr, 0) - nvl(pk.accounted_cr, 0))))
4837 or (pk.ussgl_link_to_parent_id = bp.ussgl_parent_id
4838 and pk.result_code between 'F20' and 'F29'))
4839 );
4840
4841 -- ========================= FND LOG ===========================
4842 psa_utils.debug_other_string(g_state_level,l_full_path, ' Update gl_bc_packets1 -> ' || SQL%ROWCOUNT);
4843 -- ========================= FND LOG ===========================
4844
4845 -- ========================= FND LOG ===========================
4846 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_calling_prog_flag -> ' || g_calling_prog_flag);
4847 -- ========================= FND LOG ===========================
4848
4849
4850 IF (g_calling_prog_flag = 'G') THEN
4851
4852 -- Update Result Code for Generated Transactions
4853
4854 update gl_bc_packets bp
4855 set bp.result_code = 'P26'
4856 where bp.packet_id = g_packet_id
4857 and bp.result_code between 'F00' and 'F19'
4858 and bp.ussgl_link_to_parent_id is not null
4859 and exists
4860 (
4861 select 'Corresp Original Transaction which was Overridden'
4862 from gl_bc_packets pk
4863 where pk.packet_id = g_packet_id
4864 and pk.ussgl_parent_id = bp.ussgl_link_to_parent_id
4865 and pk.result_code = 'P21'
4866 );
4867
4868 END IF;
4869
4870 -- ========================= FND LOG ===========================
4871 psa_utils.debug_other_string(g_state_level,l_full_path, ' Update gl_bc_packets2 -> ' || SQL%ROWCOUNT);
4872 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN -> TRUE ');
4873 -- ========================= FND LOG ===========================
4874
4875 return(TRUE);
4876
4877
4878 EXCEPTION
4879
4880 WHEN OTHERS THEN
4881 -- ========================= FND LOG ===========================
4882 psa_utils.debug_other_string(g_excep_level,l_full_path, ' WHEN OTHERS EXCEPTION ' || SQLERRM);
4883 -- ========================= FND LOG ===========================
4884
4885 message_token('PROCEDURE', 'Funds Checker');
4886 message_token('EVENT', SQLERRM);
4887 add_message('SQLGL', 'GL_UNHANDLED_EXCEPTION');
4888
4889 -- ========================= FND LOG ===========================
4890 psa_utils.debug_other_string(g_excep_level,l_full_path, ' RETURN -> FALSE ');
4891 -- ========================= FND LOG ===========================
4892 g_debug := g_debug||' GLXFOR Failed : '||SQLERRM;
4893 return(FALSE);
4894
4895 END glxfor;
4896
4897 /* ================================= GLXFRS ============================ */
4898
4899 -- Get Return Status
4900
4901 -- Return Code can be of one of the following values :
4902 --
4903 -- Code Meaning Description
4904 -- ---- ------- ----------------------------------------
4905 -- S Success All transactions in packet pass Funds
4906 -- Check or Funds Reservation
4907 --
4908 -- A Advisory All transactions in packet pass Funds
4909 -- Check or Funds Reservation; but some
4910 -- with Advisory warnings
4911 --
4912 -- F Failure All transactions in packet fail Funds
4913 -- Check or Funds Reservation (partial
4914 -- reservation allowed)
4915 -- OR
4916 -- One or more transactions in packet fail
4917 -- Funds Check or Funds Reservation
4918 -- (partial reservation not allowed)
4919 --
4920 -- P Partial Only part of the transactions in packet
4921 -- pass Funds Check or Funds Reservation
4922 -- (partial reservation allowed only)
4923 --
4924 -- T Fatal Irrecoverable error detected that
4925 -- prevents funds check or reservation
4926 -- from proceeding
4927 --
4928 -- Decode count fragments :
4929 -- ------------------------
4930 -- count(*)
4931 -- - Total Number of Detail Transactions in packet
4932 --
4933 -- count(decode(substr(BP.result_code, 1, 1), 'P', 1))
4934 -- - Total Number of Detail Transactions with a pass Result Code
4935 --
4936 -- count(decode(BP.result_code,
4937 -- 'P20', 1, 'P22', 1, 'P25', 1, 'P27', 1))
4938 -- - Total Number of Detail Transactions that pass with Advisory warnings
4939 --
4940 -- count(decode(substr(BP.result_code, 1, 1), 'F', 1))
4941 -- - Total Number of Detail Transactions with a fail Result Code
4942
4943 FUNCTION glxfrs RETURN BOOLEAN IS
4944
4945 cursor retcode is
4946 select decode(count(*),
4947 count(decode(substr(bp.result_code, 1, 1), 'P', 1)),
4948 decode(sign(count(decode(bp.result_code,
4949 'P20', 1,
4950 'P22', 1,
4951 'P25', 1,
4952 'P27', 1,
4953 'P31', 1,
4954 'P35', 1,
4955 'P36', 1,
4956 'P37', 1,
4957 'P38', 1,
4958 'P39', 1))), 0, 'S', 1, 'A'),
4959 count(decode(substr(bp.result_code, 1, 1), 'F', 1)),
4960 'F', decode(g_partial_resv_flag, 'Y', 'P', 'F'))
4961 from gl_bc_packets bp
4962 where bp.packet_id = g_packet_id
4963 and bp.template_id is null;
4964
4965 -- ========================= FND LOG ===========================
4966 l_full_path VARCHAR2(100);
4967 -- ========================= FND LOG ===========================
4968
4969 BEGIN
4970
4971 l_full_path := g_path || 'glxfrs';
4972
4973 -- ========================= FND LOG ===========================
4974 psa_utils.debug_other_string(g_state_level,l_full_path, ' GLXFRS --> START ');
4975 -- ========================= FND LOG ===========================
4976
4977 -- Return Code for the Packet
4978
4979 open retcode;
4980 fetch retcode into g_return_code;
4981 close retcode;
4982
4983 -- ========================= FND LOG ===========================
4984 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_return_code --> ' || g_return_code);
4985 psa_utils.debug_other_string(g_state_level,l_full_path, ' Calling glrchk ');
4986 -- ========================= FND LOG ===========================
4987
4988 if not glrchk(g_return_code) then
4989 -- ========================= FND LOG ===========================
4990 psa_utils.debug_other_string(g_state_level,l_full_path, ' glrchk --> FALSE ');
4991 -- ========================= FND LOG ===========================
4992 return(FALSE);
4993 end if;
4994
4995 -- Update Status Code and Last Update Date for all transactions
4996
4997 -- Status Codes for Funds Reservation / Check :
4998 --
4999 -- (I) For return codes S(Success), A(Advisory) or F(Failure) :
5000 --
5001 -- Process Original Status Return Code Status Code
5002 -- ----------- --------------- ----------- ---------------
5003 -- Reservation P (Pending) S (Success) A (Approved)
5004 -- Reservation P (Pending) A (Advisory) A (Approved)
5005 -- Reservation P (Pending) F (Failure) R (Rejected)
5006 -- Checking C (Checking) S (Success) S (Passed Check)
5007 -- Checking C (Checking) A (Advisory) S (Passed Check)
5008 -- Checking C (Checking) F (Failure) F (Failed Check)
5009 --
5010 -- NOTE: When Partial Reservation is not allowed, all transactions
5011 -- in a packet are updated to the same Status Code.
5012 -- e.g individual lines with Pxx result codes within a
5013 -- Failure packet get R (Rejected) Status Codes
5014 --
5015 -- (II) For return code P(Partial) :
5016 --
5017 -- Process Original Status Result Code Status Code
5018 -- ----------- --------------- ----------- ---------------
5019 -- Reservation P (Pending) Pxx A (Approved)
5020 -- Reservation P (Pending) Fxx R (Rejected)
5021 -- Checking C (Checking) Pxx S (Passed Check)
5022 -- Checking C (Checking) Fxx F (Failed Check)
5023
5024 if g_calling_prog_flag = 'G' then
5025 update gl_bc_packets bp
5026 set bp.status_code = decode(bp.status_code || g_return_code, 'PS', 'A',
5027 'PA', 'A', 'PF', 'R', 'CS', 'S', 'CA', 'S',
5028 'CF', 'F',
5029 decode(bp.status_code ||
5030 substr(bp.result_code, 1, 1), 'PP', 'A',
5031 'PF', 'R', 'CP', 'S', 'CF', 'F', 'T')),
5032 bp.last_update_date = sysdate
5033 where bp.packet_id = g_packet_id;
5034 else
5035 update gl_bc_packets bp
5036 set bp.status_code = decode(bp.status_code || g_return_code, 'PS', 'A',
5037 'PA', 'A', 'PF', 'R', 'CS', 'S', 'CA', 'S',
5038 'CF', 'F',
5039 decode(bp.status_code ||
5040 substr(bp.result_code, 1, 1), 'PP', 'A',
5041 'PF', 'R', 'CP', 'S', 'CF', 'F',
5042 decode(bp.status_code, 'F', 'F', 'R', 'R', 'T'))),
5043 bp.last_update_date = sysdate
5044 where bp.packet_id = g_packet_id;
5045 end if;
5046
5047 -- ========================= FND LOG ===========================
5048 psa_utils.debug_other_string(g_state_level,l_full_path, ' update gl_bc_packets --> ' || SQL%ROWCOUNT);
5049 -- ========================= FND LOG ===========================
5050
5051 -- Update the Result Code of all Summary Transactions that fail Funds
5052 -- Reservation to 'P23', when each of their corresponding details got
5053 -- overridden in glxfor(). This Module executes this SQL only if
5054 -- all details in the packet PASS Funds (UN)RESERVATION, i.e. Return
5055 -- Code is 'S' (Success) or 'A' (Advisory); with at least one Summary
5056 -- Transaction present
5057 --
5058 -- Code Explanation
5059 -- ---- --------------------------------------------------------
5060 -- P23 This summary account fails funds check; you overrode
5061 -- the detail(s)
5062 --
5063
5064 -- ========================= FND LOG ===========================
5065 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_fcmode --> ' || g_fcmode);
5066 IF (g_summarized_flag) THEN
5067 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_summarized_flag --> TRUE ');
5068 ELSE
5069 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_summarized_flag --> FALSE ');
5070 END IF;
5071 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_return_code --> ' || g_return_code);
5072 -- ========================= FND LOG ===========================
5073
5074 if ((g_fcmode in ('R', 'U', 'A')) and
5075 (g_summarized_flag) and
5076 (g_return_code in ('S', 'A'))) then
5077
5078 -- ========================= FND LOG ===========================
5079 psa_utils.debug_other_string(g_state_level,l_full_path, ' inside Ist IF ');
5080 -- ========================= FND LOG ===========================
5081
5082 update gl_bc_packets bp
5083 set bp.result_code = 'P23'
5084 where bp.packet_id = g_packet_id
5085 and bp.result_code like 'F%'
5086 and bp.template_id is not null;
5087
5088 -- ========================= FND LOG ===========================
5089 psa_utils.debug_other_string(g_state_level,l_full_path, ' update gl_bc_packets --> ' || SQL%ROWCOUNT);
5090 -- ========================= FND LOG ===========================
5091
5092 end if;
5093
5094
5095 -- Resummarize Amounts for all Summary Transactions if the Return Code is
5096 -- Partial and Mode is Reservation
5097
5098 -- This is necessary for partially reserved packets since for all approved
5099 -- Summary Transactions, the corresponding Detail Transactions may be
5100 -- rejected and the over-accounted Summary Amounts would affect Funds
5101 -- Check and/or Reservation for packets arriving later
5102
5103 -- e.g : Detail Transactions D1 and D2 roll up to the same Summary
5104 -- Transaction S1
5105 --
5106 -- D1: $10 (Approved)
5107 -- D2: $20 (Rejected)
5108 -- -----------------------
5109 -- S1: $30 (Approved)
5110 --
5111 -- However, since only $10 of D1 is actually approved but not the
5112 -- $20 of D2, we should update the amount approved in S1 to $10
5113 --
5114 -- This SQL also resummarizes for any Rejected Summary Transaction where one
5115 -- of more of its corresponding Details were Overridden in glxfor().
5116 -- In this case, it also updates the Status Code and Result Code of
5117 -- these Summary Transactions to 'A' (Approved) and 'P23' respectively
5118 --
5119 -- Note: If the subquery of the correlated update returns no row, the
5120 -- default action (thru' the nvls) will update all the columns
5121 -- back to their original values
5122
5123 if ((g_fcmode in ('R', 'A', 'U')) and
5124 (g_summarized_flag) and
5125 (g_return_code = 'P')) then
5126 begin
5127
5128 -- ========================= FND LOG ===========================
5129 psa_utils.debug_other_string(g_state_level,l_full_path, ' inside IInd IF ');
5130 -- ========================= FND LOG ===========================
5131
5132 update gl_bc_packets bp
5133 set (bp.entered_dr,
5134 bp.entered_cr,
5135 bp.accounted_dr,
5136 bp.accounted_cr,
5137 bp.status_code,
5138 bp.result_code) =
5139 (
5140 select nvl(sum(nvl(pk.entered_dr, 0)), bp.entered_dr),
5141 nvl(sum(nvl(pk.entered_cr, 0)), bp.entered_cr),
5142 nvl(sum(nvl(pk.accounted_dr, 0)), bp.accounted_dr),
5143 nvl(sum(nvl(pk.accounted_cr, 0)), bp.accounted_cr),
5144 nvl(max(pk.status_code), 'R'),
5145 decode(max(pk.status_code), null, bp.result_code,
5146 decode(bp.status_code, 'A', bp.result_code, 'P23'))
5147 from gl_account_hierarchies ah,
5148 gl_bc_packets pk
5149 where ah.ledger_id = g_ledger_id
5150 and ah.template_id = bp.template_id
5151 and ah.summary_code_combination_id = bp.code_combination_id
5152 and ah.detail_code_combination_id = pk.code_combination_id
5153 and pk.packet_id = g_packet_id
5154 and pk.status_code = 'A'
5155 and pk.template_id is null
5156 and pk.actual_flag = bp.actual_flag
5157 and pk.period_name = bp.period_name
5158 and pk.currency_code = bp.currency_code
5159 and pk.je_source_name = bp.je_source_name
5160 and pk.je_category_name = bp.je_category_name
5161 and (pk.budget_version_id is null
5162 or pk.budget_version_id = bp.budget_version_id)
5163 and pk.account_category_code = bp.account_category_code
5164 )
5165 where bp.packet_id = g_packet_id
5166 and bp.template_id is not null;
5167
5168 -- ========================= FND LOG ===========================
5169 psa_utils.debug_other_string(g_state_level,l_full_path, ' update gl_bc_packets --> ' || SQL%ROWCOUNT);
5170 -- ========================= FND LOG ===========================
5171
5172 end;
5173 end if;
5174
5175 -- ========================= FND LOG ===========================
5176 psa_utils.debug_other_string(g_state_level,l_full_path, ' calling glxfar ');
5177 -- ========================= FND LOG ===========================
5178
5179 if not glxfar then
5180 -- ========================= FND LOG ===========================
5181 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN --> FALSE');
5182 -- ========================= FND LOG ===========================
5183 return(FALSE);
5184 end if;
5185
5186 -- ========================= FND LOG ===========================
5187 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN --> TRUE ');
5188 -- ========================= FND LOG ===========================
5189
5190 return(TRUE);
5191
5192 EXCEPTION
5193
5194 WHEN OTHERS THEN
5195
5196 if retcode%ISOPEN then
5197 close retcode;
5198 end if;
5199
5200 message_token('PROCEDURE', 'Funds Checker');
5201 message_token('EVENT', SQLERRM);
5202 add_message('SQLGL', 'GL_UNHANDLED_EXCEPTION');
5203
5204 -- ========================= FND LOG ===========================
5205 psa_utils.debug_other_string(g_excep_level,l_full_path, ' EXCEOPTION WHEN OTHERS '|| SQLERRM);
5206 psa_utils.debug_other_string(g_excep_level,l_full_path, ' RETURN --> FALSE ');
5207 -- ========================= FND LOG ===========================
5208 g_debug := g_debug||' GLXFRS Failed : '||SQLERRM;
5209 return(FALSE);
5210
5211 END glxfrs;
5212
5213 /* ================================= GLRCHK ======================== */
5214
5215 --
5216 -- Provide callout to reconcile Return Status and Posting results.
5217 --
5218 -- After computation of the General Ledger Funds Check overall status is
5219 -- completed within glxfrs(), other parties (Grants) need to have an
5220 -- opportunity to reconcile the status with their own computation.
5221 -- Additionally, other parties need confirmation that all Funds Check
5222 -- work is completed (to reflect this within their own systems) or that
5223 -- a Fatal Error has occurred.
5224 --
5225 -- glrchk() provides this centralize place to callout to these other parties.
5226 --
5227 -- Bug 2184578
5228 -- If Standard Budgetary Control failed, CBC Journals shoud not be committed.
5229 -- This is achieved by calling function IGC_CBC_GL_FC_PKG.reconcile_glzcbc
5230 --
5231
5232 FUNCTION glrchk(post_control IN gl_bc_packets.result_code%TYPE)
5233 RETURN BOOLEAN IS
5234
5235 -- ========================= FND LOG ===========================
5236 l_full_path VARCHAR2(100);
5237 -- ========================= FND LOG ===========================
5238
5239 BEGIN
5240 l_full_path := g_path || 'glrchk.';
5241
5242 -- ========================= FND LOG ===========================
5243 psa_utils.debug_other_string(g_state_level,l_full_path, ' glrchk --> START ');
5244 psa_utils.debug_other_string(g_state_level,l_full_path, ' post_control --> ' || post_control);
5245 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_cbc_retcode --> ' || g_cbc_retcode);
5246 -- ========================= FND LOG ===========================
5247
5248 /*========================+
5249 | CBC Reconcile |
5250 +========================*/
5251
5252 -- ========================= FND LOG ===========================
5253 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_cbc_retcode-> '||g_cbc_retcode);
5254 -- ========================= FND LOG ===========================
5255
5256
5257 IF g_cbc_retcode = 1 then
5258 -- ========================= FND LOG ===========================
5259 psa_utils.debug_other_string(g_state_level,l_full_path, ' Calling CBC Reconcile ');
5260 -- ========================= FND LOG ===========================
5261
5262 DECLARE
5263 cbc_recon_stmt VARCHAR2(2000);
5264 cbc_recon_code NUMBER(15);
5265
5266 BEGIN
5267 -- ========================= FND LOG ===========================
5268 psa_utils.debug_other_string(g_state_level,l_full_path, ' GLRCHK(CBCRECONCILE) --> START ');
5269 -- ========================= FND LOG ===========================
5270
5271 cbc_recon_stmt :=
5272 'BEGIN :ret_code := IGC_CBC_GL_FC_PKG.reconcile_glzcbc(:packet_id,:sob_id,:mode); END;';
5273
5274 -- ========================= FND LOG ===========================
5275 psa_utils.debug_other_string(g_state_level,l_full_path, ' cbc_recon_stmt --> ' || cbc_recon_stmt);
5276 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_ledger_id --> ' || g_ledger_id);
5277 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_packet_id --> ' || g_packet_id);
5278 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_mode --> ' || g_fcmode);
5279 -- ========================= FND LOG ===========================
5280
5281 execute immediate cbc_recon_stmt
5282 USING IN OUT cbc_recon_code,IN g_packet_id,IN g_ledger_id,IN g_fcmode;
5283
5284 -- ========================= FND LOG ===========================
5285 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN cbc_recon_code --> ' || cbc_recon_code);
5286 -- ========================= FND LOG ===========================
5287
5288 IF cbc_recon_code = -1 THEN
5289 g_debug := g_debug||' GLRCHK Failed : CBC_RECONC_CODE = -1';
5290 return false;
5291 END IF;
5292
5293 EXCEPTION
5294 WHEN OTHERS THEN
5295 NULL;
5296
5297 END;
5298
5299 END IF;
5300
5301 -- ========================= FND LOG ===========================
5302 IF (g_psa_grantcheck) THEN
5303 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_psa_grantcheck --> TRUE ');
5304 ELSE
5305 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_psa_grantcheck --> FALSE ');
5306 END IF;
5307 -- ========================= FND LOG ===========================
5308
5309 /*========================+
5310 | GMS Reconcile |
5311 +========================*/
5312
5313 IF g_psa_grantcheck THEN
5314
5315 -- ========================= FND LOG ===========================
5316 psa_utils.debug_other_string(g_state_level,l_full_path, ' Calling GMS Reconcile ');
5317 -- ========================= FND LOG ===========================
5318
5319 DECLARE
5320
5321 gms_stmt VARCHAR2(400);
5322 gl_retcode gl_bc_packets.result_code%TYPE;
5323 gms_control gl_bc_packets.result_code%TYPE;
5324
5325 BEGIN
5326 -- ========================= FND LOG ===========================
5327 psa_utils.debug_other_string(g_state_level,l_full_path, ' GLRCHK(GMS Reconcile) --> START ');
5328 psa_utils.debug_other_string(g_state_level,l_full_path, ' post_control -> ' || post_control);
5329 -- ========================= FND LOG ===========================
5330
5331 IF post_control = 'X' OR post_control = 'Z' THEN
5332 gl_retcode := g_return_code;
5333 gms_control := post_control;
5334 ELSE
5335 gl_retcode := post_control;
5336 gms_control := gms_retcode;
5337 END IF;
5338
5339 -- ========================= FND LOG ===========================
5340 psa_utils.debug_other_string(g_state_level,l_full_path, ' gl_retcode -> ' || gl_retcode);
5341 psa_utils.debug_other_string(g_state_level,l_full_path, ' gms_control -> ' || gms_control);
5342 -- ========================= FND LOG ===========================
5343
5344 gms_stmt :=
5345 'BEGIN '||
5346 ' GMS_UTILITY.GMS_UTIL_GL_RETURN_CODE(:g_packet_id, :g_fcmode, '||
5347 ':gl_retcode, :gms_control, :g_partial_resv_flag); '||
5348 'END;';
5349
5350 -- ========================= FND LOG ===========================
5351 psa_utils.debug_other_string(g_state_level,l_full_path, ' gms_stmt -> ' || gms_stmt);
5352 -- ========================= FND LOG ===========================
5353
5354 execute immediate gms_stmt using g_packet_id, g_fcmode, in out gl_retcode,
5355 gms_control, g_partial_resv_flag;
5356
5357 -- Given that the resulting return code makes sense, replace the
5358 -- context's return code with it.
5359
5360 IF gl_retcode IS NOT NULL AND gl_retcode <> 'Z' THEN
5361
5362 -- ========================= FND LOG ===========================
5363 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_return_code -> ' || g_return_code);
5364 psa_utils.debug_other_string(g_state_level,l_full_path, ' Goto -> GMS_RECONCILE_EXIT (Normal) ');
5365 -- ========================= FND LOG ===========================
5366
5367 g_return_code := gl_retcode;
5368 goto gms_reconcile_exit;
5369
5370 END IF;
5371
5372 -- ========================= FND LOG ===========================
5373 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN -> FALSE ');
5374 -- ========================= FND LOG ===========================
5375 g_debug := g_debug||' GLRCHK Failed';
5376 RETURN(FALSE);
5377
5378 <<GMS_RECONCILE_EXIT>>
5379 null;
5380 EXCEPTION
5381
5382 WHEN OTHERS THEN
5383
5384 -- ========================= FND LOG ===========================
5385 psa_utils.debug_other_string(g_excep_level,l_full_path, ' EXCEPTION WHEN OTHERS ' || SQLERRM);
5386 psa_utils.debug_other_string(g_excep_level,l_full_path, ' RETURN -> FALSE ');
5387 -- ========================= FND LOG ===========================
5388 g_debug := g_debug||' GLRCHK Failed : '||SQLERRM;
5389 RETURN(FALSE);
5390 END;
5391
5392 END IF;
5393
5394 -- ========================= FND LOG ===========================
5395 IF (g_psa_pacheck) THEN
5396 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_psa_pacheck --> TRUE ');
5397 ELSE
5398 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_psa_pacheck --> FALSE ');
5399 END IF;
5400 -- ========================= FND LOG ===========================
5401
5402 /*========================+
5403 | PA Reconcile |
5404 +========================*/
5405
5406 IF (g_psa_pacheck) AND (post_control = 'X') THEN
5407 -- ========================= FND LOG ===========================
5408 psa_utils.debug_other_string(g_state_level,l_full_path, ' calling glzpacfm ');
5409 -- ========================= FND LOG ===========================
5410
5411 DECLARE
5412
5413 pa_stmt VARCHAR2(400);
5414 err_stg VARCHAR2(1024);
5415
5416 BEGIN
5417 -- ========================= FND LOG ===========================
5418 psa_utils.debug_other_string(g_state_level,l_full_path, ' GLRCHK(GLZPAFCM) --> START ');
5419 -- ========================= FND LOG ===========================
5420
5421 pa_stmt :=
5422 'BEGIN '||
5423 ' PA_FUNDS_CONTROL_PKG.PA_GL_CBC_CONFIRMATION(:gl_var, :g_packet_id_var, '||
5424 ':g_fcmode_var, :g_partial_resv_flag_var, NULL, NULL,:gl_retcode, :err_stg); '||
5425 'END;';
5426
5427 -- ========================= FND LOG ===========================
5428 psa_utils.debug_other_string(g_state_level,l_full_path, ' pa_stmt -> ' || pa_stmt);
5429 -- ========================= FND LOG ===========================
5430
5431 -- ========================= FND LOG ===========================
5432 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_fcmode -> ' || g_fcmode);
5433 -- ========================= FND LOG ===========================
5434
5435 IF g_fcmode = 'U' THEN
5436 EXECUTE IMMEDIATE pa_stmt USING 'GL', g_packet_id_ursvd, g_fcmode,
5437 g_partial_resv_flag, IN OUT g_return_code, OUT err_stg;
5438 ELSE
5439 EXECUTE IMMEDIATE pa_stmt USING 'GL', g_packet_id, g_fcmode,
5440 g_partial_resv_flag, IN OUT g_return_code, OUT err_stg;
5441 END IF;
5442
5443 -- ========================= FND LOG ===========================
5444 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_return_code -> ' || g_return_code);
5445 psa_utils.debug_other_string(g_state_level,l_full_path, ' err_stg -> ' || err_stg);
5446 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN -> TRUE');
5447 -- ========================= FND LOG ===========================
5448
5449 EXCEPTION
5450
5451 WHEN OTHERS THEN
5452
5453 -- ========================= FND LOG ===========================
5454 psa_utils.debug_other_string(g_excep_level,l_full_path, ' WHEN OTHERS EXCEPTION' );
5455 -- ========================= FND LOG ===========================
5456
5457 /* Even when an SQL exception is raised, if the pa_retcode */
5458 /* has been set, indicate that processing has completed. */
5459
5460 -- ========================= FND LOG ===========================
5461 psa_utils.debug_other_string(g_excep_level,l_full_path, ' RETURN -> TRUE ');
5462 -- ========================= FND LOG ===========================
5463
5464 END;
5465
5466 END IF;
5467
5468 -- ========================= FND LOG ===========================
5469 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN --> TRUE ');
5470 -- ========================= FND LOG ===========================
5471
5472 RETURN(TRUE);
5473
5474 END glrchk;
5475
5476 /* ================================ GLXFJE =========================== */
5477
5478 -- Process Journal Entries
5479 -- If the Originating Batch is Actual, the associated generated Journal Lines
5480 -- are appended/deleted to/from the corresponding headers of the Batch; the
5481 -- Control and Running Totals of the Headers and the Batch are also updated
5482 -- If the Originating Batch is Encumbrance or Budget, a separate Actual Batch
5483 -- is created/deleted for the associated generated Journal Lines
5484 -- Assumption :
5485 --
5486 -- This Module assumes that the packet being processed only includes
5487 -- Transactions from 1 single GL Journal Batch for performance reasons.
5488 -- This is how we populate gl_bc_packets currently in all GL Implementations
5489
5490 FUNCTION glxfje RETURN BOOLEAN IS
5491
5492 l_je_batch_id gl_bc_packets.je_batch_id%TYPE;
5493 l_gen_batch_id gl_bc_packets.je_batch_id%TYPE;
5494 l_actual_flag gl_bc_packets.actual_flag%TYPE;
5495 l_max_je_line_num gl_bc_packets.je_line_num%TYPE; -- bug 5139224
5496
5497
5498 cursor orig_bat is
5499 select max(bp.je_batch_id),
5500 max(bp.actual_flag),
5501 max(bp.je_line_num) -- bug 5139224
5502 from gl_bc_packets bp
5503 where bp.packet_id = g_packet_id
5504 and bp.template_id is null
5505 and bp.ussgl_link_to_parent_id is null;
5506
5507 cursor generated_bat is
5508 select distinct bp.je_batch_id
5509 from gl_bc_packets bp
5510 where bp.packet_id = g_packet_id
5511 and bp.ussgl_link_to_parent_id is not null;
5512
5513 cursor batch_id is
5514 select gl_je_batches_s.nextval
5515 from dual;
5516
5517 cursor enable_approval is
5518 SELECT enable_je_approval_flag
5519 FROM gl_ledgers_public_v
5520 WHERE ledger_id = g_ledger_id;
5521
5522 cursor je_source(c_orig_batch_id IN NUMBER) is
5523 SELECT JH.je_source je_source
5524 FROM GL_JE_HEADERS JH
5525 WHERE JH.je_header_id =
5526 (SELECT min(JH1.je_header_id)
5527 FROM GL_JE_HEADERS JH1
5528 WHERE JH1.je_batch_id = c_orig_batch_id);
5529
5530 cursor je_approval (c_je_source IN VARCHAR2) is
5531 SELECT journal_approval_flag
5532 FROM GL_JE_SOURCES
5533 WHERE je_source_name = c_je_source;
5534
5535 cursor avoid_copy_dff_attr is
5536 SELECT 'Y'
5537 FROM FND_DESCRIPTIVE_FLEXS FD
5538 WHERE application_id = 101
5539 and descriptive_flexfield_name = 'GL_JE_LINES'
5540 and context_user_override_flag = 'N'
5541 and (UPPER(default_context_field_name) IN ('CONTEXT3', 'ACCOUNT_NUM'));
5542
5543
5544 l_je_source je_source%rowtype;
5545 l_enable_app enable_approval%rowtype;
5546 l_je_approval je_approval%rowtype;
5547 l_approval_status_code gl_je_batches.approval_status_code%type;
5548 l_reversal_method VARCHAR2(1);
5549 l_seg_val_ret_code NUMBER;
5550 l_avoid_copying_attr VARCHAR2(1);
5551
5552 -- ========================= FND LOG ===========================
5553 l_full_path VARCHAR2(100);
5554 -- ========================= FND LOG ===========================
5555
5556 BEGIN
5557
5558 l_full_path := g_path || 'glxfje';
5559
5560 -- ========================= FND LOG ===========================
5561 psa_utils.debug_other_string(g_state_level,l_full_path, ' GLXFJE --> START ');
5562 -- ========================= FND LOG ===========================
5563
5564 -- Get Originating Batch ID and Actual Flag
5565 open orig_bat;
5566 fetch orig_bat into l_je_batch_id, l_actual_flag, l_max_je_line_num;
5567 close orig_bat;
5568
5569 -- ========================= FND LOG ===========================
5570 psa_utils.debug_other_string(g_state_level,l_full_path, ' l_je_batch_id -> ' || l_je_batch_id);
5571 psa_utils.debug_other_string(g_state_level,l_full_path, ' l_actual_flag -> ' || l_actual_flag);
5572 -- ========================= FND LOG ===========================
5573
5574 -- Check whether we should avoid copying DFF information
5575 open avoid_copy_dff_attr;
5576 fetch avoid_copy_dff_attr into l_avoid_copying_attr;
5577 if (avoid_copy_dff_attr%notfound) then
5578 l_avoid_copying_attr := 'N';
5579 end if;
5580 close avoid_copy_dff_attr;
5581
5582 -- ========================= FND LOG ===========================
5583 psa_utils.debug_other_string(g_state_level,l_full_path, ' l_avoid_copying_attr -> ' || l_avoid_copying_attr);
5584 -- ========================= FND LOG ===========================
5585
5586 -- Create/Delete separate Actual Batch for the generated transactions
5587 -- if the Originating Batch is Budget/Encumbrance; else, append/delete
5588 -- the generated transactions to/from the Originating Actual Batch
5589
5590 if l_actual_flag <> 'A' then
5591 -- ========================= FND LOG ===========================
5592 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_fcmode -> ' || g_fcmode);
5593 -- ========================= FND LOG ===========================
5594
5595 if g_fcmode = 'U' then
5596 -- ========================= FND LOG ===========================
5597 psa_utils.debug_other_string(g_state_level,l_full_path, ' goto delete_separate_batch label ');
5598 -- ========================= FND LOG ===========================
5599 goto delete_separate_batch;
5600 else
5601 -- ========================= FND LOG ===========================
5602 psa_utils.debug_other_string(g_state_level,l_full_path, ' goto create_separate_batch label ');
5603 -- ========================= FND LOG ===========================
5604 goto create_separate_batch;
5605 end if;
5606
5607 end if;
5608
5609 -- Insert generated transactions in the packet into gl_je_lines for all
5610 -- headers of the originating batch
5611
5612 if g_fcmode <> 'U' then
5613
5614 if (l_avoid_copying_attr = 'Y') then
5615
5616 insert into gl_je_lines
5617 (je_header_id,
5618 je_line_num,
5619 last_update_date,
5620 last_updated_by,
5621 ledger_id,
5622 code_combination_id,
5623 period_name,
5624 effective_date,
5625 status,
5626 creation_date,
5627 created_by,
5628 entered_dr,
5629 entered_cr,
5630 accounted_dr,
5631 accounted_cr,
5632 tax_code,
5633 invoice_identifier,
5634 no1,
5635 ignore_rate_flag,
5636 reference_1,
5637 reference_10)
5638 select bp.je_header_id,
5639 l_max_je_line_num + 10 * rownum, -- bug 5139224
5640 sysdate,
5641 g_user_id,
5642 g_ledger_id,
5643 bp.code_combination_id,
5644 bp.period_name,
5645 jh.default_effective_date,
5646 'U',
5647 sysdate,
5648 g_user_id,
5649 bp.entered_dr,
5650 bp.entered_cr,
5651 bp.accounted_dr,
5652 bp.accounted_cr,
5653 ' ',
5654 ' ',
5655 ' ',
5656 'Y',
5657 BP.ussgl_link_to_parent_id,
5658 'glxfje() generated: ' || g_packet_id
5659 from gl_period_statuses ps,
5660 gl_je_headers jh,
5661 gl_bc_packets bp
5662 where ps.application_id = 101
5663 and ps.ledger_id = g_ledger_id
5664 and ps.period_name = bp.period_name
5665 and jh.je_header_id = bp.je_header_id
5666 and bp.packet_id = g_packet_id
5667 and bp.ussgl_link_to_parent_id is not null;
5668
5669 -- ========================= FND LOG ===========================
5670 psa_utils.debug_other_string(g_state_level,l_full_path,
5671 ' gl_je_lines for originating batch ' || sql%ROWCOUNT);
5672 -- ========================= FND LOG ===========================
5673
5674 else
5675
5676 INSERT INTO GL_JE_LINES
5677 (je_header_id,
5678 je_line_num,
5679 last_update_date,
5680 last_updated_by,
5681 ledger_id,
5682 code_combination_id,
5683 period_name,
5684 effective_date,
5685 status,
5686 creation_date,
5687 created_by,
5688 entered_dr,
5689 entered_cr,
5690 accounted_dr,
5691 accounted_cr,
5692 tax_code,
5693 invoice_identifier,
5694 no1,
5695 ignore_rate_flag,
5696 reference_1,
5697 reference_2,
5698 reference_3,
5699 reference_4,
5700 reference_5,
5701 reference_6,
5702 reference_7,
5703 reference_8,
5704 reference_9,
5705 reference_10,
5706 context,
5707 attribute1,
5708 attribute2,
5709 attribute3,
5710 attribute4,
5711 attribute5,
5712 attribute6,
5713 attribute7,
5714 attribute8,
5715 attribute9,
5716 attribute10)
5717 SELECT
5718 BP.je_header_id,
5719 JL.je_line_num + 10*rownum,
5720 SYSDATE,
5721 g_user_id,
5722 g_ledger_id,
5723 BP.code_combination_id,
5724 BP.period_name,
5725 JL.effective_date,
5726 'U',
5727 SYSDATE,
5728 g_user_id,
5729 BP.entered_dr,
5730 BP.entered_cr,
5731 BP.accounted_dr,
5732 BP.accounted_cr,
5733 ' ',
5734 ' ',
5735 ' ',
5736 'Y',
5737 BP.ussgl_link_to_parent_id,
5738 BP.reference2,
5739 BP.reference3,
5740 BP.reference4,
5741 BP.reference5,
5742 BP.reference6,
5743 BP.reference7,
5744 BP.reference8,
5745 BP.reference9,
5746 'glxfje() generated: ' || g_packet_id /* for unrsv only */,
5747 decode(JL1.context,JL1.context3,null,JL1.context),
5748 decode(JL1.context,JL1.context3,null,JL1.attribute1),
5749 decode(JL1.context,JL1.context3,null,JL1.attribute2),
5750 decode(JL1.context,JL1.context3,null,JL1.attribute3),
5751 decode(JL1.context,JL1.context3,null,JL1.attribute4),
5752 decode(JL1.context,JL1.context3,null,JL1.attribute5),
5753 decode(JL1.context,JL1.context3,null,JL1.attribute6),
5754 decode(JL1.context,JL1.context3,null,JL1.attribute7),
5755 decode(JL1.context,JL1.context3,null,JL1.attribute8),
5756 decode(JL1.context,JL1.context3,null,JL1.attribute9),
5757 decode(JL1.context,JL1.context3,null,JL1.attribute10)
5758 FROM
5759 GL_PERIOD_STATUSES PS,
5760 GL_JE_LINES JL,
5761 GL_JE_LINES JL1,
5762 GL_BC_PACKETS BP
5763 WHERE
5764 PS.application_id = 101
5765 AND PS.ledger_id = g_ledger_id
5766 AND PS.period_name = BP.period_name
5767 AND JL.je_header_id = BP.je_header_id
5768 AND JL.je_line_num = (SELECT max(JL1.je_line_num)
5769 FROM GL_JE_LINES JL1
5770 WHERE JL1.je_header_id = BP.je_header_id)
5771 AND BP.packet_id = g_packet_id
5772 AND BP.ussgl_link_to_parent_id IS NOT NULL
5773 AND JL1.je_header_id = BP.je_header_id
5774 AND JL1.je_line_num = BP.je_line_num;
5775
5776 -- ========================= FND LOG ===========================
5777 psa_utils.debug_other_string(g_state_level,l_full_path,
5778 ' Insert GL_JE_LINES -> ' || sql%ROWCOUNT);
5779 -- ========================= FND LOG ===========================
5780
5781 end if;
5782 else
5783
5784 -- For Unreservation, delete previously appended generated transactions
5785 -- from gl_je_lines
5786
5787 delete from gl_je_lines jl
5788 where jl.je_header_id in
5789 (
5790 select distinct bp.je_header_id
5791 from gl_bc_packets bp
5792 where bp.packet_id = g_packet_id
5793 and bp.ussgl_link_to_parent_id IS NOT NULL
5794 )
5795 and jl.reference_10 = 'glxfje() generated: ' || g_packet_id_ursvd;
5796
5797 -- ========================= FND LOG ===========================
5798 psa_utils.debug_other_string(g_state_level,l_full_path,
5799 ' delete gl_je_lines - Unreservation ' || sql%ROWCOUNT);
5800 -- ========================= FND LOG ===========================
5801
5802 end if;
5803
5804
5805 -- Update Control Total and Running Totals of all headers with generated
5806 -- transactions appended/deleted
5807
5808 update gl_je_headers jh
5809 set (jh.control_total,
5810 jh.running_total_dr,
5811 jh.running_total_cr,
5812 jh.running_total_accounted_dr,
5813 jh.running_total_accounted_cr) =
5814 (
5815 select decode(jh.control_total, null, null, jh.control_total +
5816 sum(nvl(bp.entered_dr, 0)) *
5817 decode(g_fcmode, 'U', -1, 1)),
5818 nvl(jh.running_total_dr, 0) + sum(nvl(bp.entered_dr, 0)) *
5819 decode(g_fcmode, 'U', -1, 1),
5820 nvl(jh.running_total_cr, 0) + sum(nvl(bp.entered_cr, 0)) *
5821 decode(g_fcmode, 'U', -1, 1),
5822 nvl(jh.running_total_accounted_dr, 0) +
5823 sum(nvl(bp.accounted_dr, 0)) *
5824 decode(g_fcmode, 'U', -1, 1),
5825 nvl(jh.running_total_accounted_cr, 0) +
5826 sum(nvl(bp.accounted_cr, 0)) *
5827 decode(g_fcmode, 'U', -1, 1)
5828 from gl_bc_packets bp
5829 where bp.packet_id = g_packet_id
5830 and bp.je_batch_id = jh.je_batch_id
5831 and bp.je_header_id = jh.je_header_id
5832 and bp.ussgl_link_to_parent_id is not null
5833 )
5834 where jh.je_header_id in
5835 (
5836 select distinct je_header_id
5837 from gl_bc_packets bp1
5838 where bp1.packet_id = g_packet_id
5839 and bp1.ussgl_link_to_parent_id is not null
5840 );
5841
5842 -- ========================= FND LOG ===========================
5843 psa_utils.debug_other_string(g_state_level,l_full_path,
5844 ' Update Control Total and Running Totals - gl_je_headers ' || SQL%ROWCOUNT);
5845 -- ========================= FND LOG ===========================
5846
5847
5848 -- Update Batch Control Total, Running Totals, Budgetary Control Status and
5849 -- Packet ID
5850
5851 update gl_je_batches jb
5852 set (jb.control_total,
5853 jb.running_total_dr,
5854 jb.running_total_cr,
5855 jb.running_total_accounted_dr,
5856 jb.running_total_accounted_cr,
5857 jb.budgetary_control_status,
5858 jb.packet_id) =
5859 (
5860 select decode(jb.control_total, null, null, jb.control_total +
5861 sum(nvl(bp.entered_dr, 0)) *
5862 decode(g_fcmode, 'U', -1, 1)),
5863 nvl(jb.running_total_dr, 0) + sum(nvl(bp.entered_dr, 0)) *
5864 decode(g_fcmode, 'U', -1, 1),
5865 nvl(jb.running_total_cr, 0) + sum(nvl(bp.entered_cr, 0)) *
5866 decode(g_fcmode, 'U', -1, 1),
5867 nvl(jb.running_total_accounted_dr, 0) +
5868 sum(nvl(bp.accounted_dr, 0)) * decode(g_fcmode, 'U', -1, 1),
5869 nvl(jb.running_total_accounted_cr, 0) +
5870 sum(nvl(bp.accounted_cr, 0)) * decode(g_fcmode, 'U', -1, 1),
5871 decode(g_fcmode, 'U', 'R', 'P'),
5872 decode(g_fcmode, 'U', null, jb.packet_id)
5873 from gl_bc_packets bp
5874 where bp.packet_id = g_packet_id
5875 and bp.je_batch_id = jb.je_batch_id
5876 and bp.ussgl_link_to_parent_id is not null
5877 )
5878 where jb.je_batch_id = l_je_batch_id;
5879
5880 -- ========================= FND LOG ===========================
5881 psa_utils.debug_other_string(g_state_level,l_full_path,
5882 ' Update gl_je_batches - Batch Control Total, Running Totals, ' ||
5883 ' Budgetary Control Status ' || SQL%ROWCOUNT);
5884 psa_utils.debug_other_string(g_state_level,l_full_path, ' goto normal_exit label ');
5885 -- ========================= FND LOG ===========================
5886
5887 -- Invoke GL API to fix the GL_JE_SEGMENT_VALUES table.
5888 -- We invoke this API with batch_id parameter so that it works with both inserts/deletes
5889
5890 l_seg_val_ret_code := gl_je_segment_values_pkg.insert_batch_segment_values(l_je_batch_id);
5891
5892 -- Exit since Originating Batch is Actual
5893 goto normal_exit;
5894
5895 <<create_separate_batch>>
5896
5897 -- ========================= FND LOG ===========================
5898 psa_utils.debug_other_string(g_state_level,l_full_path, ' Reached create_separate_batch label ');
5899 -- ========================= FND LOG ===========================
5900
5901 -- Get new Batch ID from Sequence
5902 open batch_id;
5903 fetch batch_id into l_gen_batch_id;
5904 close batch_id;
5905
5906 open enable_approval;
5907 fetch enable_approval into l_enable_app;
5908 close enable_approval;
5909
5910 -- ========================= FND LOG ===========================
5911 psa_utils.debug_other_string(g_state_level,l_full_path, ' l_gen_batch_id -> '|| l_gen_batch_id);
5912 psa_utils.debug_other_string(g_state_level,l_full_path, ' l_enable_app -> '|| l_enable_app.enable_je_approval_flag);
5913 -- ========================= FND LOG ===========================
5914
5915 if l_enable_app.enable_je_approval_flag = 'Y' then
5916
5917 open je_source(l_je_batch_id);
5918 fetch je_source into l_je_source;
5919 close je_source;
5920
5921 -- ========================= FND LOG ===========================
5922 psa_utils.debug_other_string(g_state_level,l_full_path, ' l_je_source -> '|| l_je_source.je_source);
5923 -- ========================= FND LOG ===========================
5924
5925 open je_approval(l_je_source.je_source);
5926 fetch je_approval into l_je_approval;
5927 close je_approval;
5928
5929 -- ========================= FND LOG ===========================
5930 psa_utils.debug_other_string(g_state_level,l_full_path, ' l_je_approval -> '|| l_je_approval.journal_approval_flag);
5931 -- ========================= FND LOG ===========================
5932
5933 if l_je_approval.journal_approval_flag = 'Y' then
5934 l_approval_status_code := 'R';
5935 else
5936 l_approval_status_code := 'Z';
5937 end if;
5938
5939 else
5940 l_approval_status_code := 'Z';
5941 end if;
5942
5943 -- ========================= FND LOG ===========================
5944 psa_utils.debug_other_string(g_state_level,l_full_path,
5945 ' l_approval_status_code -> '|| l_approval_status_code);
5946 -- ========================= FND LOG ===========================
5947
5948 -- Create new Actual Batch for the Generated Transactions
5949 insert into gl_je_batches
5950 (je_batch_id,
5951 last_update_date,
5952 last_updated_by,
5953 set_of_books_id_11i,
5954 name,
5955 status,
5956 status_verified,
5957 actual_flag,
5958 default_effective_date,
5959 creation_date,
5960 created_by,
5961 default_period_name,
5962 date_created,
5963 description,
5964 running_total_dr,
5965 running_total_cr,
5966 running_total_accounted_dr,
5967 running_total_accounted_cr,
5968 budgetary_control_status,
5969 packet_id,
5970 average_journal_flag,
5971 approval_status_code,
5972 chart_of_accounts_id,
5973 period_set_name,
5974 accounted_period_type)
5975 select l_gen_batch_id,
5976 sysdate,
5977 g_user_id,
5978 g_ledger_id,
5979 substrb('CJE: ' || min(jb.name) ||' '||
5980 to_char(sysdate)||
5981 to_char(sysdate,' HH24:MI:SS: ')||
5982 'A', 1, 100),
5983 'U',
5984 'N',
5985 'A',
5986 min(jb.default_effective_date),
5987 sysdate,
5988 g_user_id,
5989 min(bp.period_name),
5990 sysdate,
5991 decode(min(jb.description), null, null,
5992 substrb('CJE: ' || min(jb.description), 1, 240)),
5993 sum(nvl(bp.entered_dr, 0)),
5994 sum(nvl(bp.entered_cr, 0)),
5995 sum(nvl(bp.accounted_dr, 0)),
5996 sum(nvl(bp.accounted_cr, 0)),
5997 'P',
5998 null, /* For Disabling Unreservation on Generated Batches */
5999 min(jb.average_journal_flag),
6000 l_approval_status_code,
6001 min(jb.chart_of_accounts_id),
6002 min(jb.period_set_name),
6003 min(jb.accounted_period_type)
6004 from gl_period_statuses ps,
6005 gl_bc_packets bp,
6006 gl_je_batches jb
6007 where ps.application_id = 101
6008 and ps.ledger_id = g_ledger_id
6009 and ps.period_name = bp.period_name
6010 and bp.packet_id = g_packet_id
6011 and bp.ussgl_link_to_parent_id is not null
6012 and jb.je_batch_id = l_je_batch_id;
6013
6014
6015 -- ========================= FND LOG ===========================
6016 psa_utils.debug_other_string(g_state_level,l_full_path,
6017 ' Creating new actual bacth - gl_je_batches -> '|| SQL%ROWCOUNT);
6018 -- ========================= FND LOG ===========================
6019
6020
6021 -- ========================= FND LOG ===========================
6022 psa_utils.debug_other_string(g_state_level,l_full_path, ' Calling glurevd ');
6023 -- ========================= FND LOG ===========================
6024
6025 DECLARE
6026
6027 CURSOR batch_sources IS
6028 SELECT je_header_id, je_category, je_source, period_name
6029 FROM gl_je_headers
6030 WHERE je_batch_id = l_je_batch_id;
6031
6032 BEGIN
6033 FOR x IN batch_sources
6034 LOOP
6035
6036 -- ========================= FND LOG ===========================
6037 psa_utils.debug_other_string(g_state_level,l_full_path, ' x.je_header_id -> '|| x.je_header_id);
6038 psa_utils.debug_other_string(g_state_level,l_full_path, ' x.je_category -> '|| x.je_category);
6039 psa_utils.debug_other_string(g_state_level,l_full_path, ' x.je_source -> '|| x.je_source);
6040 psa_utils.debug_other_string(g_state_level,l_full_path, ' x.period_name -> '|| x.period_name);
6041 -- ========================= FND LOG ===========================
6042
6043 IF NOT ( glurevd(p_ledger_id => g_ledger_id,
6044 p_je_category => x.je_category,
6045 p_je_source => x.je_source,
6046 p_je_period => x.period_name,
6047 p_je_date => sysdate,
6048 x_reversal_method => l_reversal_method,
6049 p_balance_type => 'A')) THEN
6050
6051 -- ========================= FND LOG ===========================
6052 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN -> FALSE ');
6053 -- ========================= FND LOG ===========================
6054 g_debug := g_debug||' GLXFJE Failed : glurevd returned FALSE';
6055 return (FALSE);
6056 END IF;
6057
6058 -- Create associated headers for the new Actual Batch
6059 insert into gl_je_headers
6060 (je_header_id,
6061 last_update_date,
6062 last_updated_by,
6063 ledger_id,
6064 je_category,
6065 je_source,
6066 period_name,
6067 name,
6068 currency_code,
6069 status,
6070 date_created,
6071 accrual_rev_flag,
6072 multi_bal_seg_flag,
6073 actual_flag,
6074 conversion_flag,
6075 default_effective_date,
6076 creation_date,
6077 created_by,
6078 je_batch_id,
6079 description,
6080 currency_conversion_rate,
6081 currency_conversion_type,
6082 currency_conversion_date,
6083 attribute1,
6084 accrual_rev_change_sign_flag,
6085 tax_status_code)
6086 select gl_je_headers_s.nextval,
6087 sysdate,
6088 g_user_id,
6089 g_ledger_id,
6090 jh.je_category,
6091 jh.je_source,
6092 jh.period_name,
6093 substrb('CJE: ' || jh.name ||' '||
6094 to_char(sysdate)||
6095 to_char(sysdate,' HH24:MI:SS'),1,100),
6096 jh.currency_code,
6097 'U',
6098 sysdate,
6099 'N',
6100 'N',
6101 'A',
6102 'N',
6103 jh.default_effective_date,
6104 sysdate,
6105 g_user_id,
6106 l_gen_batch_id,
6107 decode(jh.description, null, null,
6108 substrb('CJE: ' || jh.description, 1, 240)),
6109 1,
6110 'User',
6111 sysdate,
6112 to_char(jh.je_header_id),
6113 l_reversal_method,
6114 'N'
6115 from gl_je_headers jh
6116 where jh.je_batch_id = l_je_batch_id
6117 and jh.je_header_id = x.je_header_id
6118 and exists
6119 (
6120 select 'JE headers with associated generated transactions'
6121 from gl_bc_packets bp
6122 where bp.packet_id = g_packet_id
6123 and bp.je_batch_id = l_je_batch_id
6124 and bp.je_header_id = jh.je_header_id
6125 and bp.ussgl_link_to_parent_id is not null
6126 );
6127
6128
6129 -- ========================= FND LOG ===========================
6130 psa_utils.debug_other_string(g_state_level,l_full_path,
6131 ' Insert gl_je_headers - Headers for Actual Batches ' || SQL%ROWCOUNT);
6132 -- ========================= FND LOG ===========================
6133 END LOOP;
6134 END;
6135
6136 -- Update running totals of associated headers
6137
6138 update gl_je_headers jh
6139 set (jh.running_total_dr,
6140 jh.running_total_cr,
6141 jh.running_total_accounted_dr,
6142 jh.running_total_accounted_cr) =
6143 (
6144 select sum(nvl(bp.entered_dr, 0)),
6145 sum(nvl(bp.entered_cr, 0)),
6146 sum(nvl(bp.accounted_dr, 0)),
6147 sum(nvl(bp.accounted_cr, 0))
6148 from gl_bc_packets bp
6149 where bp.packet_id = g_packet_id
6150 and bp.je_batch_id = l_je_batch_id
6151 and bp.je_header_id = to_number(jh.attribute1)
6152 and bp.ussgl_link_to_parent_id is not null
6153 )
6154 where JH.je_batch_id = l_gen_batch_id;
6155
6156 -- ========================= FND LOG ===========================
6157 psa_utils.debug_other_string(g_state_level,l_full_path,
6158 ' update gl_je_headers - running totals - ' || SQL%ROWCOUNT);
6159 -- ========================= FND LOG ===========================
6160
6161 -- Insert generated transactions in packet into gl_je_lines
6162 if (l_avoid_copying_attr = 'Y') then
6163
6164 insert into gl_je_lines
6165 (je_header_id,
6166 je_line_num,
6167 last_update_date,
6168 last_updated_by,
6169 ledger_id,
6170 code_combination_id,
6171 period_name,
6172 effective_date,
6173 status,
6174 creation_date,
6175 created_by,
6176 entered_dr,
6177 entered_cr,
6178 accounted_dr,
6179 accounted_cr,
6180 tax_code,
6181 invoice_identifier,
6182 no1,
6183 ignore_rate_flag,
6184 reference_10)
6185 select jh.je_header_id,
6186 10 * row_number() over (partition by jh.je_header_id
6187 order by jh.je_header_id),
6188 sysdate,
6189 g_user_id,
6190 g_ledger_id,
6191 bp.code_combination_id,
6192 bp.period_name,
6193 jh.default_effective_date,
6194 'U',
6195 sysdate,
6196 g_user_id,
6197 bp.entered_dr,
6198 bp.entered_cr,
6199 bp.accounted_dr,
6200 bp.accounted_cr,
6201 ' ',
6202 ' ',
6203 ' ',
6204 'Y',
6205 'glxfje() generated: ' || g_packet_id
6206 from gl_je_headers jh,
6207 gl_bc_packets bp
6208 where jh.je_batch_id = l_gen_batch_id
6209 and jh.attribute1 = to_char(bp.je_header_id)
6210 and bp.packet_id = g_packet_id
6211 and bp.ussgl_link_to_parent_id is not null;
6212
6213 else
6214
6215 INSERT INTO GL_JE_LINES
6216 (je_header_id,
6217 je_line_num,
6218 last_update_date,
6219 last_updated_by,
6220 ledger_id,
6221 code_combination_id,
6222 period_name,
6223 effective_date,
6224 status,
6225 creation_date,
6226 created_by,
6227 entered_dr,
6228 entered_cr,
6229 accounted_dr,
6230 accounted_cr,
6231 tax_code,
6232 invoice_identifier,
6233 no1,
6234 ignore_rate_flag,
6235 reference_10,
6236 context,
6237 attribute1,
6238 attribute2,
6239 attribute3,
6240 attribute4,
6241 attribute5,
6242 attribute6,
6243 attribute7,
6244 attribute8,
6245 attribute9,
6246 attribute10)
6247 SELECT
6248 min(JH.je_header_id),
6249 10*count(BP1.rowid),
6250 SYSDATE,
6251 g_user_id,
6252 g_ledger_id,
6253 min(BP.code_combination_id),
6254 min(BP.period_name),
6255 min(JH.default_effective_date),
6256 'U',
6257 SYSDATE,
6258 g_ledger_id,
6259 min(BP.entered_dr),
6260 min(BP.entered_cr),
6261 min(BP.accounted_dr),
6262 min(BP.accounted_cr),
6263 ' ',
6264 ' ',
6265 ' ',
6266 'Y',
6267 'glxfje() generated: ' || g_packet_id, /* for unrsv only */
6268 decode(min(JL.context),min(JL.context3),null,min(JL.context)),
6269 decode(min(JL.context),min(JL.context3),null,min(JL.attribute1)),
6270 decode(min(JL.context),min(JL.context3),null,min(JL.attribute2)),
6271 decode(min(JL.context),min(JL.context3),null,min(JL.attribute3)),
6272 decode(min(JL.context),min(JL.context3),null,min(JL.attribute4)),
6273 decode(min(JL.context),min(JL.context3),null,min(JL.attribute5)),
6274 decode(min(JL.context),min(JL.context3),null,min(JL.attribute6)),
6275 decode(min(JL.context),min(JL.context3),null,min(JL.attribute7)),
6276 decode(min(JL.context),min(JL.context3),null,min(JL.attribute8)),
6277 decode(min(JL.context),min(JL.context3),null,min(JL.attribute9)),
6278 decode(min(JL.context),min(JL.context3),null,min(JL.attribute10))
6279 FROM
6280 GL_JE_HEADERS JH,
6281 GL_BC_PACKETS BP1,
6282 GL_BC_PACKETS BP,
6283 GL_JE_LINES JL
6284 WHERE
6285 JH.je_batch_id = l_gen_batch_id
6286 AND JH.attribute1 = to_char(BP.je_header_id)
6287 AND BP1.packet_id = BP.packet_id
6288 AND BP1.je_batch_id = BP.je_batch_id
6289 AND BP1.je_header_id = BP.je_header_id
6290 AND BP1.rowid <= BP.rowid
6291 AND BP1.ussgl_link_to_parent_id IS NOT NULL
6292 AND BP.packet_id = g_packet_id
6293 AND BP.ussgl_link_to_parent_id IS NOT NULL
6294 AND JL.je_header_id = BP.je_header_id
6295 AND JL.je_line_num = BP.je_line_num
6296 GROUP BY BP.rowid;
6297
6298 end if;
6299
6300 -- ========================= FND LOG ===========================
6301 psa_utils.debug_other_string(g_state_level,l_full_path,
6302 ' Insert gl_je_lines - ' || SQL%ROWCOUNT);
6303 -- ========================= FND LOG ===========================
6304
6305
6306 -- Update je_batch_id of all associated generated transactions from the
6307 -- ID of the Originating Batch to that of the newly created batch so that
6308 -- posting deletes only these packet rows
6309
6310 update gl_bc_packets bp
6311 set bp.je_batch_id = l_gen_batch_id
6312 where bp.packet_id = g_packet_id
6313 and bp.ussgl_link_to_parent_id is not null;
6314
6315 -- ========================= FND LOG ===========================
6316 psa_utils.debug_other_string(g_state_level,l_full_path,
6317 ' update gl_bc_packets - je_bacth_id - ' || SQL%ROWCOUNT);
6318 -- ========================= FND LOG ===========================
6319
6320 -- Clean up attribute1 in gl_je_headers (contains header id of the
6321 -- originating line)
6322
6323 update gl_je_headers jh
6324 set jh.attribute1 = null
6325 where jh.je_batch_id = l_gen_batch_id;
6326
6327 -- ========================= FND LOG ===========================
6328 psa_utils.debug_other_string(g_state_level,l_full_path,
6329 ' update gl_je_headers -> ' || SQL%ROWCOUNT);
6330 psa_utils.debug_other_string(g_state_level,l_full_path,
6331 ' goto normal_exit label ');
6332 -- ========================= FND LOG ===========================
6333
6334 -- Invoke GL API to fix the GL_JE_SEGMENT_VALUES table.
6335
6336 l_seg_val_ret_code := gl_je_segment_values_pkg.insert_batch_segment_values(l_gen_batch_id);
6337
6338 goto normal_exit;
6339
6340 <<delete_separate_batch>>
6341 -- ========================= FND LOG ===========================
6342 psa_utils.debug_other_string(g_state_level,l_full_path,
6343 ' Reached delete_seperate_batch label ');
6344 -- ========================= FND LOG ===========================
6345
6346 -- Delete all previously created associated generated transactions from
6347 -- gl_je_lines
6348
6349 delete from gl_je_lines jl
6350 where jl.je_header_id in
6351 (
6352 select distinct jh.je_header_id
6353 from gl_je_headers jh,
6354 gl_bc_packets bp
6355 where jh.je_batch_id = bp.je_batch_id
6356 and bp.packet_id = g_packet_id
6357 and bp.ussgl_link_to_parent_id is not null
6358 )
6359 and jl.reference_10 = 'glxfje() generated: ' || g_packet_id_ursvd;
6360
6361 -- ========================= FND LOG ===========================
6362 psa_utils.debug_other_string(g_state_level,l_full_path,
6363 ' Delete gl_je_lines - ' || SQL%ROWCOUNT);
6364 -- ========================= FND LOG ===========================
6365
6366 -- Delete all associated headers of the generated transactions
6367
6368 delete from gl_je_headers jh
6369 where jh.je_batch_id in
6370 (
6371 select distinct bp.je_batch_id
6372 from gl_bc_packets bp
6373 where bp.packet_id = g_packet_id
6374 and bp.ussgl_link_to_parent_id is not null
6375 );
6376
6377 -- ========================= FND LOG ===========================
6378 psa_utils.debug_other_string(g_state_level,l_full_path,
6379 ' Delete gl_je_headers - ' || SQL%ROWCOUNT);
6380 -- ========================= FND LOG ===========================
6381
6382 -- Delete the associated batch of the generated transactions
6383
6384 FOR x IN generated_bat
6385 LOOP
6386 delete from gl_je_batches jb
6387 where jb.je_batch_id = x.je_batch_id;
6388
6389 -- ========================= FND LOG ===========================
6390 psa_utils.debug_other_string(g_state_level,l_full_path,
6391 ' Delete gl_je_batches - ' || SQL%ROWCOUNT);
6392 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN - TRUE ');
6393 -- ========================= FND LOG ===========================
6394
6395 -- Invoke the GL API to fix the GL_JE_SEGMENT_VALUES table
6396
6397 l_seg_val_ret_code := gl_je_segment_values_pkg.insert_batch_segment_values(x.je_batch_id);
6398 END LOOP;
6399
6400
6401 return(TRUE);
6402
6403 <<normal_exit>>
6404 -- ========================= FND LOG ===========================
6405 psa_utils.debug_other_string(g_state_level,l_full_path,
6406 ' Reached normal_exit label');
6407 -- ========================= FND LOG ===========================
6408
6409 if NOT g_conc_flag AND l_actual_flag = 'A' then
6410 COMMIT;
6411 g_requery_flag := TRUE;
6412 end if;
6413
6414 -- ========================= FND LOG ===========================
6415 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN - TRUE ');
6416 -- ========================= FND LOG ===========================
6417 return(TRUE);
6418
6419
6420 EXCEPTION
6421
6422 WHEN OTHERS THEN
6423
6424 if orig_bat%ISOPEN then
6425 close orig_bat;
6426 end if;
6427
6428 if batch_id%ISOPEN then
6429 close batch_id;
6430 end if;
6431
6432 message_token('PROCEDURE', 'Funds Checker');
6433 message_token('EVENT', SQLERRM);
6434 add_message('SQLGL', 'GL_UNHANDLED_EXCEPTION');
6435
6436 -- ========================= FND LOG ===========================
6437 psa_utils.debug_other_string(g_excep_level,l_full_path, ' EXCEPTION WHEN OTHERS ' || SQLERRM);
6438 psa_utils.debug_other_string(g_excep_level,l_full_path, ' RETURN - FALSE ');
6439 -- ========================= FND LOG ===========================
6440 g_debug := g_debug||' GLXFJE Failed : '||SQLERRM;
6441 return(FALSE);
6442
6443 END glxfje;
6444
6445 /* ============================= GLXFPP ============================= */
6446
6447 -- Purge Packets after Funds Check
6448
6449 -- This Module provides a way for any external Funds Check implementation
6450 -- to rollback Funds Reserved after the Funds Checker call. This must be
6451 -- called before any commit that would otherwise confirm the final Funds
6452 -- Check Status of the packet
6453
6454 -- This Module deletes all transaction lines of a packet in gl_bc_packets and
6455 -- the associated Arrival Order record in gl_bc_packet_arrival_order
6456
6457 -- This Module also deletes the corresponding records for a packet being
6458 -- Unreserved
6459
6460 -- This Function is invoked by any Module that needs to purge all packet
6461 -- related information after the Funds Checker call
6462
6463
6464 -- Parameters :
6465 -- p_packetid : Packet ID
6466 -- p_packetid_ursvd : Unreservation Packet ID. Defaults to 0
6467
6468 PROCEDURE glxfpp(p_packetid IN NUMBER,
6469 p_packetid_ursvd IN NUMBER) IS
6470
6471 -- ========================= FND LOG ===========================
6472 l_full_path VARCHAR2(100);
6473 -- ========================= FND LOG ===========================
6474
6475 BEGIN
6476
6477 l_full_path := g_path || 'glxfpp1';
6478
6479 -- ========================= FND LOG ===========================
6480 psa_utils.debug_other_string(g_state_level,l_full_path, ' GLXFPP1 --> START ');
6481 -- ========================= FND LOG ===========================
6482
6483 -- Delete Packet Transactions
6484 delete from gl_bc_packets bp
6485 where bp.packet_id in (p_packetid, p_packetid_ursvd);
6486
6487 -- ========================= FND LOG ===========================
6488 psa_utils.debug_other_string(g_state_level,l_full_path,
6489 ' delete from gl_bc_packets ' || SQL%ROWCOUNT);
6490 -- ========================= FND LOG ===========================
6491
6492 -- Delete Packet Arrival Order Record
6493 delete from gl_bc_packet_arrival_order ao
6494 where ao.packet_id in (p_packetid, p_packetid_ursvd);
6495
6496 -- ========================= FND LOG ===========================
6497 psa_utils.debug_other_string(g_state_level,l_full_path,
6498 ' delete from gl_bc_packet_arrival_order ' || SQL%ROWCOUNT);
6499 -- ========================= FND LOG ===========================
6500
6501 EXCEPTION
6502
6503 WHEN OTHERS THEN
6504
6505 message_token('PROCEDURE', 'Funds Checker');
6506 message_token('EVENT', SQLERRM);
6507 add_message('SQLGL', 'GL_UNHANDLED_EXCEPTION');
6508
6509 -- ========================= FND LOG ===========================
6510 psa_utils.debug_other_string(g_excep_level,l_full_path, ' EXCEPTION WHEN OTHERS ' || SQLERRM);
6511 -- ========================= FND LOG ===========================
6512
6513 END glxfpp;
6514
6515 PROCEDURE glxfpp(p_eventid IN NUMBER) IS
6516
6517 -- ========================= FND LOG ===========================
6518 l_full_path VARCHAR2(100);
6519 -- ========================= FND LOG ===========================
6520
6521 BEGIN
6522
6523 l_full_path := g_path || 'glxfpp2';
6524
6525 -- ========================= FND LOG ===========================
6526 psa_utils.debug_other_string(g_state_level,l_full_path, ' GLXFPP2 --> START ');
6527 -- ========================= FND LOG ===========================
6528
6529 -- Delete Packet Transactions
6530 delete from gl_bc_packets bp
6531 where bp.event_id = p_eventid;
6532
6533 -- ========================= FND LOG ===========================
6534 psa_utils.debug_other_string(g_state_level,l_full_path,
6535 ' delete from gl_bc_packets ' || SQL%ROWCOUNT);
6536 -- ========================= FND LOG ===========================
6537
6538 -- Delete Packet Arrival Order Record
6539 delete from gl_bc_packet_arrival_order ao
6540 where ao.packet_id in (select packet_id
6541 from gl_bc_packets
6542 where event_id = p_eventid);
6543
6544 -- ========================= FND LOG ===========================
6545 psa_utils.debug_other_string(g_state_level,l_full_path,
6546 ' delete from gl_bc_packet_arrival_order ' || SQL%ROWCOUNT);
6547 -- ========================= FND LOG ===========================
6548
6549 -- Delete History Record
6550 delete from gl_bc_packets_hists bp
6551 where bp.event_id = p_eventid;
6552
6553 -- ========================= FND LOG ===========================
6554 psa_utils.debug_other_string(g_state_level,l_full_path,
6555 ' delete from gl_bc_packets_hists ' || SQL%ROWCOUNT);
6556 -- ========================= FND LOG ===========================
6557
6558 EXCEPTION
6559
6560 WHEN OTHERS THEN
6561
6562 message_token('PROCEDURE', 'Funds Checker');
6563 message_token('EVENT', SQLERRM);
6564 add_message('SQLGL', 'GL_UNHANDLED_EXCEPTION');
6565
6566 -- ========================= FND LOG ===========================
6567 psa_utils.debug_other_string(g_excep_level,l_full_path, ' EXCEPTION WHEN OTHERS ' || SQLERRM);
6568 -- ========================= FND LOG ===========================
6569
6570 END glxfpp;
6571
6572 /* ============================ GLXFUF ============================ */
6573
6574 -- Update Status Code for Transactions to Fatal
6575
6576 -- Updates Status Code for all transactions in the Packet to 'T'; it also
6577 -- updates affect_funds_flag in gl_bc_packet_arrival_order to 'N' so that
6578 -- the available Funds calculation of packets arriving later is not affected
6579 -- in case an irrecoverable error halts Funds Check. SQLs for updating the
6580 -- columns are not guaranteed to succeed in many drastic cases. However, this
6581 -- step tries to ensure that the current packet does not affect the Funds
6582 -- Available calculation for packets arriving later
6583
6584 -- The final cleanup is done by the Sweeper program, which deletes all packets
6585 -- with Status 'T', as well as all packets with Status 'P' (Pending) which are
6586 -- older than a specific (relatively long) time interval. This remedies for
6587 -- cases where the update could not be done in this Module
6588
6589 FUNCTION glxfuf RETURN BOOLEAN IS
6590 -- ========================= FND LOG ===========================
6591 l_full_path VARCHAR2(100);
6592 -- ========================= FND LOG ===========================
6593 BEGIN
6594
6595 l_full_path := g_path || 'glxfuf';
6596
6597 -- ========================= FND LOG ===========================
6598 psa_utils.debug_other_string(g_state_level,l_full_path, ' glxfuf -> START ');
6599 -- ========================= FND LOG ===========================
6600
6601 -- Update Status Code for the Packet Transactions
6602 update gl_bc_packets bp
6603 set bp.status_code = 'T'
6604 where bp.packet_id = g_packet_id;
6605
6606 -- ========================= FND LOG ===========================
6607 psa_utils.debug_other_string(g_state_level,l_full_path,
6608 ' g_packet_id -> ' || g_packet_id );
6609 psa_utils.debug_other_string(g_state_level,l_full_path,
6610 ' update gl_bc_packets with T -> ' || SQL%ROWCOUNT );
6611 -- ========================= FND LOG ===========================
6612
6613 -- Update Affect Funds Flag
6614 update gl_bc_packet_arrival_order ao
6615 set ao.affect_funds_flag = 'N'
6616 where ao.packet_id = g_packet_id;
6617
6618 -- ========================= FND LOG ===========================
6619 psa_utils.debug_other_string(g_state_level,l_full_path,
6620 ' update gl_bc_packet_arrival_order to N -> ' || SQL%ROWCOUNT );
6621 -- ========================= FND LOG ===========================
6622
6623 if not glrchk('Z') then
6624 -- ========================= FND LOG ===========================
6625 psa_utils.debug_other_string(g_state_level,l_full_path, ' glrchk(Z) -> FALSE' );
6626 -- ========================= FND LOG ===========================
6627 null;
6628 end if;
6629
6630 -- ========================= FND LOG ===========================
6631 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN --> TRUE' );
6632 -- ========================= FND LOG ===========================
6633 return(TRUE);
6634
6635 EXCEPTION
6636
6637 WHEN OTHERS THEN
6638
6639 message_token('PROCEDURE', 'Funds Checker');
6640 message_token('EVENT', SQLERRM);
6641 add_message('SQLGL', 'GL_UNHANDLED_EXCEPTION');
6642
6643 -- ========================= FND LOG ===========================
6644 psa_utils.debug_other_string(g_excep_level,l_full_path, ' EXCEPTION WHEN OTHERS ' || SQLERRM );
6645 psa_utils.debug_other_string(g_excep_level,l_full_path, ' RETURN --> FALSE' );
6646 -- ========================= FND LOG ===========================
6647 g_debug := g_debug||' GLXFUF Failed : '||SQLERRM;
6648 return(FALSE);
6649
6650 END glxfuf;
6651
6652 /* =============================== MESSAGE_TOKEN ======================= */
6653
6654 -- Add Token and Value to the Message Token array
6655
6656 PROCEDURE message_token(tokname IN VARCHAR2,
6657 tokval IN VARCHAR2) IS
6658
6659 l_full_path VARCHAR2(100);
6660
6661 BEGIN
6662
6663 l_full_path := g_path||'Message_Token';
6664
6665 if g_no_msg_tokens is null then
6666 g_no_msg_tokens := 1;
6667 else
6668 g_no_msg_tokens := g_no_msg_tokens + 1;
6669 end if;
6670
6671 -- ========================= FND LOG ===========================
6672 psa_utils.debug_other_string(g_excep_level,l_full_path, ' g_no_msg_tokens -> ' || g_no_msg_tokens );
6673 -- ========================= FND LOG ===========================
6674
6675 msg_tok_names(g_no_msg_tokens) := tokname;
6676 msg_tok_val(g_no_msg_tokens) := tokval;
6677
6678 END message_token;
6679
6680 /* =========================== ADD_MESSAGE ============================== */
6681
6682 -- Sets the Message Stack
6683
6684 PROCEDURE add_message(appname IN VARCHAR2,
6685 msgname IN VARCHAR2) IS
6686
6687 i BINARY_INTEGER;
6688 l_full_path VARCHAR2(100);
6689
6690 BEGIN
6691
6692 l_full_path := g_path||'Add_Message';
6693
6694 if ((appname is not null) and
6695 (msgname is not null)) then
6696
6697 FND_MESSAGE.SET_NAME(appname, msgname);
6698
6699 if g_no_msg_tokens is not null then
6700
6701 for i in 1..g_no_msg_tokens loop
6702 FND_MESSAGE.SET_TOKEN(msg_tok_names(i), msg_tok_val(i));
6703 end loop;
6704
6705 end if;
6706
6707 end if;
6708
6709 -- Clear Message Token stack
6710 g_no_msg_tokens := 0;
6711
6712 -- ========================= FND LOG ===========================
6713 psa_utils.debug_other_string(g_excep_level,l_full_path, ' g_no_msg_tokens -> ' || g_no_msg_tokens );
6714 -- ========================= FND LOG ===========================
6715
6716
6717 END add_message;
6718
6719
6720 /* ========================== FV_PREPAY_PKG ========================== */
6721
6722 FUNCTION fv_prepay_pkg RETURN BOOLEAN IS
6723
6724 -- Bug 3861686, added subquery to get the owner of the package.
6725
6726 CURSOR c_fv_prepay_pkg is
6727 SELECT DISTINCT 'Y' status
6728 FROM ALL_OBJECTS
6729 WHERE object_name = 'FV_AP_PREPAY_PKG'
6730 AND object_type = 'PACKAGE'
6731 AND owner = (SELECT oracle_username
6732 FROM fnd_oracle_userid
6733 WHERE read_only_flag = 'U')
6734 AND status = 'VALID';
6735
6736 CURSOR c_packet_count(c_packet_id IN NUMBER) is
6737 SELECT count(*) pkt_cnt
6738 FROM gl_bc_packets
6739 WHERE packet_id = c_packet_id;
6740
6741 cursor c_batch_id (c_packet_id IN NUMBER) is
6742 SELECT 'Y' batch_id
6743 FROM GL_BC_PACKETS
6744 WHERE packet_id = c_packet_id
6745 AND je_batch_id IS NOT NULL
6746 AND rownum = 1;
6747
6748 l_fv_prepay_pkg c_fv_prepay_pkg%rowtype;
6749 l_packet_count c_packet_count%rowtype;
6750 l_batch_id c_batch_id%rowtype;
6751
6752 fv_prepay_stmt VARCHAR2(2000);
6753 p_packet_id gl_bc_packets.packet_id%type;
6754 p_status NUMBER(15);
6755 l_full_path VARCHAR2(100);
6756
6757 BEGIN
6758
6759 l_full_path := g_path||'Fv_Prepay_pkg';
6760 if g_fv_prepay_prof then
6761
6762 p_packet_id := g_packet_id;
6763
6764 if g_fcmode IN ( 'C', 'R' ) then
6765
6766 open c_fv_prepay_pkg;
6767 fetch c_fv_prepay_pkg
6768 into l_fv_prepay_pkg;
6769 close c_fv_prepay_pkg;
6770
6771 -- ========================= FND LOG ===========================
6772 psa_utils.debug_other_string(g_excep_level,l_full_path, ' l_fv_prepay_pkg.status -> ' || l_fv_prepay_pkg.status );
6773 -- ========================= FND LOG ===========================
6774
6775
6776 if l_fv_prepay_pkg.status = 'Y' then
6777
6778 open c_packet_count(p_packet_id);
6779 fetch c_packet_count
6780 into l_packet_count;
6781 close c_packet_count;
6782
6783 if l_packet_count.pkt_cnt IS NOT NULL then
6784
6785 open c_batch_id(p_packet_id);
6786 fetch c_batch_id
6787 into l_batch_id;
6788 close c_batch_id;
6789
6790 if l_batch_id.batch_id IS NULL then
6791
6792 fv_prepay_stmt :=
6793 'BEGIN FV_AP_PREPAY_PKG.CREATE_PREPAY_LINES(:p_packet_id, :p_status); END;';
6794
6795 execute immediate fv_prepay_stmt USING IN p_packet_id, OUT p_status;
6796
6797 -- 0 : Success 1 : Failure
6798
6799 if p_status = 1 then
6800
6801 message_token('PROCEDURE', 'FV_AP_PREPAY_PKG.CREATE_PREPAY_LINES Returned Failure');
6802 message_token('EVENT', SQLERRM);
6803 add_message('SQLGL', 'GL_UNHANDLED_EXCEPTION');
6804 g_debug := g_debug||' FV_PREPAY_PKG Failed : FV_AP_PREPAY_PKG.CREATE_PREPAY_LINES
6805 Returned Failure';
6806 return(FALSE);
6807
6808 end if;
6809 end if;
6810 end if;
6811 end if;
6812 end if;
6813 end if;
6814
6815 RETURN TRUE;
6816
6817 EXCEPTION
6818 WHEN OTHERS THEN
6819 message_token('PROCEDURE', 'FV_AP_PREPAY_PKG.CREATE_PREPAY_LINES Returned Failure');
6820 message_token('EVENT', SQLERRM);
6821 add_message('SQLGL', 'GL_UNHANDLED_EXCEPTION');
6822
6823 -- ========================= FND LOG ===========================
6824 psa_utils.debug_other_string(g_excep_level,l_full_path, ' EXCEPTION WHEN OTHERS ' || SQLERRM);
6825 psa_utils.debug_other_string(g_excep_level,l_full_path, ' RETURN FALSE');
6826 -- ========================= FND LOG ===========================
6827
6828 g_debug := g_debug||' FV_PREPAY_PKG Failed : '||SQLERRM;
6829 return FALSE;
6830
6831 END fv_prepay_pkg;
6832
6833
6834
6835 /* ============================= GLXFAR ================================ */
6836
6837 -- Update affect_funds_flag in gl_bc_packet_arrival
6838 --
6839 -- This is called from glxfrs() and is executed in an autonomous scope
6840 -- so that the calling programs work is not commited.
6841 --
6842
6843 FUNCTION glxfar RETURN BOOLEAN IS
6844 PRAGMA AUTONOMOUS_TRANSACTION;
6845 -- ========================= FND LOG ===========================
6846 l_full_path VARCHAR2(100);
6847 -- ========================= FND LOG ===========================
6848
6849 BEGIN
6850
6851 l_full_path := g_path || 'glxfar';
6852
6853 -- ========================= FND LOG ===========================
6854 psa_utils.debug_other_string(g_state_level,l_full_path, ' GLXFAR -> START ');
6855 -- ========================= FND LOG ===========================
6856
6857 -- Update Affect Funds Flag to 'N' if Mode is Reservation and Return Code
6858 -- is Failure
6859
6860 if ((g_fcmode <> 'C') and
6861 (g_return_code = 'F')) then
6862 begin
6863
6864 update gl_bc_packet_arrival_order ao
6865 set ao.affect_funds_flag = 'N'
6866 where ao.packet_id = g_packet_id;
6867
6868 -- ========================= FND LOG ===========================
6869 psa_utils.debug_other_string(g_state_level,l_full_path,
6870 ' update gl_bc_packet_arrival_order -> ' || SQL%ROWCOUNT);
6871 -- ========================= FND LOG ===========================
6872
6873 -- Commit so that a later rollback does not reset this flag
6874 commit;
6875
6876 -- ========================= FND LOG ===========================
6877 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN - TRUE');
6878 -- ========================= FND LOG ===========================
6879 RETURN (TRUE);
6880
6881 end;
6882 end if;
6883
6884 commit;
6885 -- ========================= FND LOG ===========================
6886 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN - TRUE');
6887 -- ========================= FND LOG ===========================
6888 RETURN (TRUE);
6889
6890 EXCEPTION
6891
6892 WHEN OTHERS THEN
6893
6894 message_token('PROCEDURE', 'Funds Checker : glxfar');
6895 message_token('EVENT', SQLERRM);
6896 add_message('SQLGL', 'GL_UNHANDLED_EXCEPTION');
6897
6898 -- ========================= FND LOG ===========================
6899 psa_utils.debug_other_string(g_excep_level,l_full_path, ' EXCEPTION WHEN OTHERS ' || SQLERRM);
6900 psa_utils.debug_other_string(g_excep_level,l_full_path, ' RETURN - FALSE');
6901 -- ========================= FND LOG ===========================
6902
6903 g_debug := g_debug||' GLXFAR Failed : '||SQLERRM;
6904 -- bug 3471744
6905 rollback;
6906 return (FALSE);
6907
6908 END;
6909
6910 /* =============================== GLXCON ================================ */
6911
6912 FUNCTION glxcon RETURN BOOLEAN IS
6913 others EXCEPTION;
6914 -- ========================= FND LOG ===========================
6915 l_full_path VARCHAR2(100);
6916 -- ========================= FND LOG ===========================
6917
6918 BEGIN
6919
6920 l_full_path := g_path || 'glxcon.';
6921
6922 -- ========================= FND LOG ===========================
6923 psa_utils.debug_other_string(g_state_level,l_full_path, ' GLXCON -> START ');
6924 psa_utils.debug_other_string(g_state_level,l_full_path, ' Calling glxfrs .. ');
6925 -- ========================= FND LOG ===========================
6926
6927 -- Get Return Status
6928 if not glxfrs then
6929 -- ========================= FND LOG ===========================
6930 psa_utils.debug_other_string(g_state_level,l_full_path, ' GLXFRS - RETURN FALSE ');
6931 psa_utils.debug_other_string(g_state_level,l_full_path, ' goto fatal_error label ');
6932 -- ========================= FND LOG ===========================
6933 goto fatal_error;
6934 end if;
6935
6936 -- ========================= FND LOG ===========================
6937 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_fcmode -> ' || g_fcmode);
6938 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_return_code -> '|| g_return_code);
6939 -- ========================= FND LOG ===========================
6940
6941 -- Process Journal Entries Module if all transactions pass Funds
6942 -- (Un)Reservation and Append JE Flag is set
6943
6944 if ((g_fcmode in ('R', 'U', 'A', 'F')) and
6945 (g_return_code in ('S', 'A'))) then
6946
6947 if g_append_je_flag then
6948 -- ========================= FND LOG ===========================
6949 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_append_je_flag -> TRUE');
6950 psa_utils.debug_other_string(g_state_level,l_full_path, ' Calling glxfje ..');
6951 -- ========================= FND LOG ===========================
6952
6953 if not glxfje then
6954 -- ========================= FND LOG ===========================
6955 psa_utils.debug_other_string(g_state_level,l_full_path, ' GLXFJE RETURN FALSE ');
6956 psa_utils.debug_other_string(g_state_level,l_full_path, ' goto fatal_error label ');
6957 -- ========================= FND LOG ===========================
6958 goto fatal_error;
6959 end if;
6960
6961 end if;
6962
6963 -- Delete the Packet being Unreserved and the generated Unreserved
6964 -- Packet if it passes Funds Unreservation
6965
6966 if g_fcmode = 'U' then
6967
6968 -- ========================= FND LOG ===========================
6969 psa_utils.debug_other_string(g_state_level,l_full_path, ' Calling glxfpp .. ');
6970 -- ========================= FND LOG ===========================
6971 glxfpp(g_packet_id, g_packet_id_ursvd);
6972
6973 -- If Journal Entries were deleted then Commit
6974 if g_append_je_flag then
6975 -- ========================= FND LOG ===========================
6976 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_append_je_flag -> TRUE ');
6977 psa_utils.debug_other_string(g_state_level,l_full_path, ' COMMIT ');
6978 -- ========================= FND LOG ===========================
6979 commit;
6980 end if;
6981
6982 end if;
6983 end if;
6984
6985 -- ========================= FND LOG ===========================
6986 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN -> TRUE ');
6987 -- ========================= FND LOG ===========================
6988 return(TRUE);
6989
6990 <<fatal_error>>
6991 -- ========================= FND LOG ===========================
6992 psa_utils.debug_other_string(g_state_level,l_full_path, ' Reached fatal_error label ');
6993 psa_utils.debug_other_string(g_state_level,l_full_path, ' Calling glxfuf .. ');
6994 -- ========================= FND LOG ===========================
6995
6996 if not glxfuf then
6997 -- ========================= FND LOG ===========================
6998 psa_utils.debug_other_string(g_state_level,l_full_path, ' GLXFUF - RETURN FALSE ');
6999 psa_utils.debug_other_string(g_state_level,l_full_path, ' RASIE OTHERS ');
7000 -- ========================= FND LOG ===========================
7001 raise others;
7002 end if;
7003
7004 -- ========================= FND LOG ===========================
7005 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN -> FALSE ');
7006 -- ========================= FND LOG ===========================
7007 g_debug := g_debug||' GLXCON Failed';
7008 return(FALSE);
7009
7010 EXCEPTION
7011
7012 WHEN OTHERS THEN
7013
7014 message_token('PROCEDURE', 'Funds Checker');
7015 message_token('EVENT', SQLERRM);
7016 add_message('SQLGL', 'GL_UNHANDLED_EXCEPTION');
7017
7018 -- ========================= FND LOG ===========================
7019 psa_utils.debug_other_string(g_excep_level,l_full_path, ' EXCEPTION WHEN OTHERS ' || SQLERRM);
7020 psa_utils.debug_other_string(g_excep_level,l_full_path, ' RETURN -> FALSE ');
7021 -- ========================= FND LOG ===========================
7022 g_debug := g_debug||' GLXCON Failed : '||SQLERRM;
7023 return(FALSE);
7024
7025 END glxcon;
7026
7027 /*=======================================================================+
7028 | Function : GLUREVD |
7029 | Description : This is a replica of function glurevd_default_reversal |
7030 | in file $GL_TOP/src/utils/glurevd.lpc |
7031 +=======================================================================*/
7032
7033 FUNCTION glurevd ( p_ledger_id NUMBER,
7034 p_je_category VARCHAR2,
7035 p_je_source VARCHAR2,
7036 p_je_period VARCHAR2,
7037 p_je_date DATE,
7038 x_reversal_method OUT NOCOPY VARCHAR2,
7039 p_balance_type VARCHAR2) RETURN BOOLEAN IS
7040
7041 l_je_reversal_date DATE;
7042 l_reversal_method VARCHAR2(1);
7043 l_reversal_period VARCHAR2(15);
7044 l_reversal_date DATE;
7045 -- ========================= FND LOG ===========================
7046 l_full_path VARCHAR2(100);
7047 -- ========================= FND LOG ===========================
7048 BEGIN
7049
7050 l_full_path := g_path || 'glurevd';
7051
7052 -- ========================= FND LOG ===========================
7053 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_ledger_id -> ' || p_ledger_id);
7054 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_je_category -> ' || p_je_category);
7055 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_je_source -> ' || p_je_source);
7056 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_je_period -> ' || p_je_period);
7057 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_je_date -> '
7058 || to_char(p_je_date, 'DD-MON-YYYY'));
7059 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_balance_type -> ' || p_balance_type);
7060 -- ========================= FND LOG ===========================
7061
7062 IF (p_balance_type = 'A') THEN
7063 BEGIN
7064 GL_AUTOREVERSE_DATE_PKG.GET_REVERSAL_PERIOD_DATE(
7065 x_ledger_id => p_ledger_id,
7066 x_je_category => p_je_category,
7067 x_je_source => p_je_source,
7068 x_je_period_name => p_je_period,
7069 x_je_date => p_je_date,
7070 x_reversal_method => l_reversal_method,
7071 x_reversal_period => l_reversal_period,
7072 x_reversal_date => l_reversal_date);
7073 EXCEPTION
7074 WHEN OTHERS THEN
7075 -- ========================= FND LOG ===========================
7076 psa_utils.debug_other_string(g_excep_level,l_full_path,
7077 'Call to GL_AUTOREVERSE_DATE_PKG raised unhandled exception - '
7078 ||sqlcode||' - '||sqlerrm);
7079 psa_utils.debug_unexpected_msg(l_full_path);
7080 -- ========================= FND LOG ===========================
7081
7082 GL_AUTOREVERSE_DATE_PKG.get_default_reversal_method(
7083 g_ledger_id, p_je_category, l_reversal_method);
7084
7085 -- ========================= FND LOG ===========================
7086 psa_utils.debug_other_string(g_excep_level,l_full_path,
7087 'l_reversal_method value returned by get_default_reversal_method : '||l_reversal_method);
7088 -- ========================= FND LOG ===========================
7089
7090 END;
7091
7092 ELSE
7093
7094 GL_AUTOREVERSE_DATE_PKG.get_default_reversal_method(
7095 g_ledger_id, p_je_category, l_reversal_method);
7096
7097 -- ========================= FND LOG ===========================
7098 psa_utils.debug_other_string(g_excep_level,l_full_path,
7099 'l_reversal_method value returned by get_default_reversal_method : '||l_reversal_method);
7100 -- ========================= FND LOG ===========================
7101
7102 END IF;
7103
7104 IF (l_reversal_method IS NOT NULL) THEN
7105
7106 -- ========================= FND LOG ===========================
7107 psa_utils.debug_other_string(g_excep_level,l_full_path,'x_reversal_method -> l_reversal_method');
7108 psa_utils.debug_other_string(g_excep_level,l_full_path,'Return -> True');
7109 -- ========================= FND LOG ===========================
7110
7111 x_reversal_method := l_reversal_method;
7112 return TRUE;
7113 ELSE
7114 -- ========================= FND LOG ===========================
7115 psa_utils.debug_other_string(g_excep_level,l_full_path,'Return -> False');
7116 -- ========================= FND LOG ===========================
7117
7118 return FALSE;
7119 END IF;
7120
7121 EXCEPTION
7122 WHEN OTHERS THEN
7123 -- ========================= FND LOG ===========================
7124 psa_utils.debug_other_string(g_excep_level,l_full_path,
7125 'Exception raised in main body execution - '||sqlcode||' - '||sqlerrm);
7126 psa_utils.debug_unexpected_msg(l_full_path);
7127 -- ========================= FND LOG ===========================
7128 g_debug := g_debug||' GLUREVD Failed : '||SQLERRM;
7129 x_reversal_method := NULL;
7130 return FALSE;
7131
7132 END glurevd;
7133
7134 /*=======================================================================+
7135 | Function : GL_CONFIRM_OVERRIDE |
7136 | Description : Applicable on for GL. This function is added so that GL |
7137 | can pop up a window for confirming override of the trx |
7138 | and once the user decides, GL invokes this function |
7139 | so that funds check can proceed accordingly. |
7140 +=======================================================================*/
7141
7142 FUNCTION gl_confirm_override(p_ledgerid IN NUMBER,
7143 p_packetid IN NUMBER,
7144 p_mode IN VARCHAR2 DEFAULT 'C',
7145 p_override IN VARCHAR2 DEFAULT 'N',
7146 p_conc_flag IN VARCHAR2 DEFAULT 'N',
7147 p_user_id IN NUMBER DEFAULT NULL,
7148 p_user_resp_id IN NUMBER DEFAULT NULL,
7149 p_calling_prog_flag IN VARCHAR2 DEFAULT 'G',
7150 p_confirm_override IN VARCHAR2 DEFAULT 'Y',
7151 p_return_code OUT NOCOPY VARCHAR2,
7152 p_unrsv_packet_id OUT NOCOPY NUMBER) RETURN BOOLEAN IS
7153
7154
7155 cursor append_je is
7156 select 'Associated Generated JEs to be appended or inserted'
7157 from dual
7158 where exists
7159 (
7160 select 'Associated Generated Row from existing GL Batch'
7161 from gl_bc_packets bp
7162 where bp.packet_id = g_packet_id
7163 and bp.je_batch_id is not null
7164 and bp.je_batch_id >= 0
7165 and bp.ussgl_transaction_code is not null
7166 );
7167
7168 OTHERS EXCEPTION;
7169 l_dummy VARCHAR2(100);
7170 -- ========================= FND LOG ===========================
7171 l_full_path VARCHAR2(100);
7172 -- ========================= FND LOG ===========================
7173 BEGIN
7174 l_full_path := g_path || 'gl_confirm_override';
7175
7176 -- ========================= FND LOG ===========================
7177 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_ledgerid -> ' || p_ledgerid);
7178 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_packetid -> ' || p_packetid);
7179 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_mode -> ' || p_mode);
7180 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_override -> ' || p_override);
7181 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_conc_flag -> ' || p_conc_flag);
7182 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_user_id -> ' || p_user_id);
7183 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_calling_prog_flag -> ' || p_calling_prog_flag);
7184 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_confirm_override -> ' || p_confirm_override);
7185 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_user_resp_id -> ' || p_user_resp_id);
7186 -- ========================= FND LOG ===========================
7187
7188 if p_calling_prog_flag <> 'G' then
7189
7190 -- =========================== FND LOG ===========================
7191 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_calling_prog_flag <> G -> raise others');
7192 -- ========================= FND LOG =============================
7193
7194 raise others;
7195 end if;
7196
7197 -- Initialize Global Variables
7198 if not glxfin(p_ledgerid => p_ledgerid,
7199 p_packetid => p_packetid,
7200 p_mode => p_mode,
7201 p_override => p_override,
7202 p_conc_flag => p_conc_flag,
7203 p_user_id => p_user_id,
7204 p_user_resp_id => p_user_resp_id,
7205 p_calling_prog_flag => p_calling_prog_flag) then
7206
7207 -- =========================== FND LOG ===========================
7208 psa_utils.debug_other_string(g_state_level,l_full_path, ' glxfin --> RETURN FALSE -> goto fatal_error');
7209 -- ========================= FND LOG =============================
7210
7211 goto fatal_error;
7212 end if;
7213
7214 -- Override Transactions
7215 if (g_override_flag) and (p_confirm_override = 'Y') then
7216 -- =========================== FND LOG ===========================
7217 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_override_flag --> TRUE ');
7218 -- ========================= FND LOG =============================
7219
7220 if not glxfor then
7221 -- =========================== FND LOG ===========================
7222 psa_utils.debug_other_string(g_state_level,l_full_path, ' glxfor --> RETURN FALSE -> goto fatal_error');
7223 -- ========================= FND LOG =============================
7224 goto fatal_error;
7225 end if;
7226
7227 else
7228 -- =========================== FND LOG ===========================
7229 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_override_flag --> FALSE ');
7230 -- ========================= FND LOG =============================
7231 end if;
7232
7233 -- =========================== FND LOG ===========================
7234 psa_utils.debug_other_string(g_state_level,l_full_path, ' Calling glxcon ');
7235 -- ========================= FND LOG =============================
7236
7237 open append_je;
7238 fetch append_je into l_dummy;
7239 if (append_je%found) then
7240 g_append_je_flag := true;
7241 else
7242 g_append_je_flag := false;
7243 end if;
7244 close append_je;
7245
7246 -- Set Result Codes, Return Code, Append Journal Logic
7247 if not glxcon then
7248 -- =========================== FND LOG ===========================
7249 psa_utils.debug_other_string(g_state_level,l_full_path, ' glxcon --> RETURN FALSE -> goto fatal_error');
7250 -- ========================= FND LOG =============================
7251 goto fatal_error;
7252 end if;
7253
7254 -- =========================== FND LOG ===========================
7255 psa_utils.debug_other_string(g_state_level,l_full_path, ' Calling glrchk ');
7256 -- ========================= FND LOG =============================
7257
7258 if not glrchk('X') then
7259 -- =========================== FND LOG ===========================
7260 psa_utils.debug_other_string(g_state_level,l_full_path, ' glrchk(X) --> RETURN FALSE -> goto fatal_error');
7261 -- ========================= FND LOG =============================
7262 goto fatal_error;
7263 end if;
7264
7265 -- =========================== FND LOG ===========================
7266 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_return_code = g_return_code --> ' || g_return_code);
7267 -- ========================= FND LOG =============================
7268
7269 p_return_code := g_return_code;
7270
7271 -- =========================== FND LOG ===========================
7272 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN --> TRUE ');
7273 -- ========================= FND LOG =============================
7274
7275 IF (p_mode = 'U' AND NOT g_requery_flag) THEN
7276 p_unrsv_packet_id := p_packetid;
7277 -- ========================= FND LOG ===========================
7278 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_unrsv_packet_id --> ' || p_unrsv_packet_id );
7279 -- ========================= FND LOG ===========================
7280 END IF;
7281
7282 -- If g_requery_flag is TRUE set p_return_code = "Q"
7283 -- for calling form (MJE) to requery instead of the
7284 -- regular commit. [p_return code "Q" => Success/Advisory]
7285
7286 IF g_requery_flag THEN
7287 p_return_code := 'Q';
7288 -- ========================= FND LOG ===========================
7289 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_return_code --> Q => Success/Advisory ');
7290 -- ========================= FND LOG ===========================
7291 END IF;
7292
7293 -- ========================= FND LOG ===========================
7294 psa_utils.debug_other_string(g_state_level,l_full_path, ' Return -> True');
7295 -- ========================= FND LOG ===========================
7296
7297 return(TRUE);
7298
7299 <<fatal_error>>
7300
7301 -- =========================== FND LOG ===========================
7302 psa_utils.debug_other_string(g_state_level,l_full_path, ' Reached FATAL ERROR LABEL ');
7303 -- ========================= FND LOG =============================
7304
7305 if not glxfuf then
7306 -- =========================== FND LOG ===========================
7307 psa_utils.debug_other_string(g_state_level,l_full_path, ' glxfuf --> RETURN FALSE -> RAISE OTHERS');
7308 -- ========================= FND LOG =============================
7309 raise others;
7310 end if;
7311
7312 -- =========================== FND LOG ===========================
7313 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN -> FALSE ');
7314 -- ========================= FND LOG =============================
7315
7316 g_debug := g_debug||' GL_CONFIRM_OVERRIDE Failed';
7317 return(FALSE);
7318
7319 EXCEPTION
7320
7321 WHEN OTHERS THEN
7322 -- =========================== FND LOG ===========================
7323 psa_utils.debug_other_string(g_excep_level,l_full_path, ' EXCEPTION WHEN OTHERS ' || SQLERRM);
7324 psa_utils.debug_other_string(g_excep_level,l_full_path, ' RETURN -> FALSE ');
7325 -- ========================= FND LOG =============================
7326
7327 message_token('PROCEDURE', 'Funds Checker');
7328 message_token('EVENT', SQLERRM);
7329 add_message('SQLGL', 'GL_UNHANDLED_EXCEPTION');
7330 g_debug := g_debug||' GL_CONFIRM_OVERRIDE Failed : '||SQLERRM;
7331 return(FALSE);
7332
7333 END gl_confirm_override;
7334
7335
7336 /*=======================================================================+
7337 | Function : OPTIMIZE_PACKETS |
7338 | Description : Invoked by bc_optimizer rountine. This acts as a pvt |
7339 | function. Function deletes rows from gl_bc_packets and |
7340 | inserts them in gl_bc_packets_hists. Only rows with |
7341 | status_code R, S, F, T, P, C are deleted. |
7342 +=======================================================================*/
7343
7344 PROCEDURE optimize_packets (p_ledger_id IN NUMBER, p_purge_days IN NUMBER) IS
7345 l_full_path VARCHAR2(100);
7346 BEGIN
7347 l_full_path := g_path||'Optimize_Packets';
7348
7349 /*-----------------------------------------------------------------------+
7350 | New criteria for deleting rows from gl_bc_packets is as below: |
7351 | |
7352 | Status_Code: |
7353 | =========== |
7354 | R, S, F, T - All rows for the p_ledger_id |
7355 | - These rows should get inserted in gl_bc_packets_hists |
7356 | |
7357 | P, C - All rows for the p_ledger_id for which session has |
7358 | expired or which are older than 5 days (120 hours) |
7359 | - These rows should not be stored in gl_bc_packets_hists |
7360 | |
7361 +----------------------------------------------------------------------*/
7362
7363
7364 DELETE from gl_bc_packets Q
7365 where
7366 Q.status_code IN ('P', 'C')
7367 and ((((sysdate - Q.last_update_date)*24) > 48) OR
7368 (NOT EXISTS (SELECT 'x'
7369 FROM v$session
7370 WHERE audsid = Q.session_id
7371 and Serial# = Q.serial_id)));
7372
7373 -- =========================== FND LOG ===========================
7374 psa_utils.debug_other_string(g_state_level,l_full_path, ' Delete gl_bc_packets 1 deleted ' || SQL%ROWCOUNT || ' rows');
7375 -- ========================= FND LOG =============================
7376
7377 LOOP -- Bug 10171221
7378
7379 DELETE from gl_bc_packets Q
7380 where
7381 Q.ledger_id = p_ledger_id
7382 and Q.status_code in ('R','S','F', 'T') -- Bug 10171221
7383 and rownum < 501 returning
7384 PACKET_ID,
7385 LEDGER_ID,
7386 JE_SOURCE_NAME,
7387 JE_CATEGORY_NAME,
7388 CODE_COMBINATION_ID,
7389 ACTUAL_FLAG,
7390 PERIOD_NAME,
7391 PERIOD_YEAR,
7392 PERIOD_NUM,
7393 QUARTER_NUM,
7394 CURRENCY_CODE,
7395 STATUS_CODE,
7396 LAST_UPDATE_DATE,
7397 LAST_UPDATED_BY,
7398 BUDGET_VERSION_ID,
7399 ENCUMBRANCE_TYPE_ID,
7400 TEMPLATE_ID,
7401 ENTERED_DR,
7402 ENTERED_CR,
7403 ACCOUNTED_DR,
7404 ACCOUNTED_CR,
7405 USSGL_TRANSACTION_CODE,
7406 ORIGINATING_ROWID,
7407 ACCOUNT_SEGMENT_VALUE,
7408 AUTOMATIC_ENCUMBRANCE_FLAG,
7409 FUNDING_BUDGET_VERSION_ID,
7410 FUNDS_CHECK_LEVEL_CODE,
7411 AMOUNT_TYPE,
7412 BOUNDARY_CODE,
7413 TOLERANCE_PERCENTAGE,
7414 TOLERANCE_AMOUNT,
7415 OVERRIDE_AMOUNT,
7416 DR_CR_CODE,
7417 ACCOUNT_TYPE,
7418 ACCOUNT_CATEGORY_CODE,
7419 EFFECT_ON_FUNDS_CODE,
7420 RESULT_CODE,
7421 BUDGET_POSTED_BALANCE,
7422 ACTUAL_POSTED_BALANCE,
7423 ENCUMBRANCE_POSTED_BALANCE,
7424 BUDGET_APPROVED_BALANCE,
7425 ACTUAL_APPROVED_BALANCE,
7426 ENCUMBRANCE_APPROVED_BALANCE,
7427 BUDGET_PENDING_BALANCE,
7428 ACTUAL_PENDING_BALANCE,
7429 ENCUMBRANCE_PENDING_BALANCE,
7430 REFERENCE1,
7431 REFERENCE2,
7432 REFERENCE3,
7433 REFERENCE4,
7434 REFERENCE5,
7435 JE_BATCH_NAME,
7436 JE_BATCH_ID,
7437 JE_HEADER_ID,
7438 JE_LINE_NUM,
7439 JE_LINE_DESCRIPTION,
7440 REFERENCE6,
7441 REFERENCE7,
7442 REFERENCE8,
7443 REFERENCE9,
7444 REFERENCE10,
7445 REFERENCE11,
7446 REFERENCE12,
7447 REFERENCE13,
7448 REFERENCE14,
7449 REFERENCE15,
7450 REQUEST_ID,
7451 USSGL_PARENT_ID,
7452 USSGL_LINK_TO_PARENT_ID,
7453 EVENT_ID,
7454 AE_HEADER_ID,
7455 AE_LINE_NUM,
7456 BC_DATE,
7457 SOURCE_DISTRIBUTION_TYPE,
7458 SOURCE_DISTRIBUTION_ID_CHAR_1,
7459 SOURCE_DISTRIBUTION_ID_CHAR_2,
7460 SOURCE_DISTRIBUTION_ID_CHAR_3,
7461 SOURCE_DISTRIBUTION_ID_CHAR_4,
7462 SOURCE_DISTRIBUTION_ID_CHAR_5,
7463 SOURCE_DISTRIBUTION_ID_NUM_1,
7464 SOURCE_DISTRIBUTION_ID_NUM_2,
7465 SOURCE_DISTRIBUTION_ID_NUM_3,
7466 SOURCE_DISTRIBUTION_ID_NUM_4,
7467 SOURCE_DISTRIBUTION_ID_NUM_5,
7468 SESSION_ID,
7469 SERIAL_ID,
7470 APPLICATION_ID,
7471 ENTITY_ID,
7472 GROUP_ID
7473 bulk collect into g_bc_pkts_hist;
7474
7475 -- =========================== FND LOG ===========================
7476 psa_utils.debug_other_string(g_state_level,l_full_path, ' Delete gl_bc_packets 2 deleted ' || SQL%ROWCOUNT || ' rows');
7477 -- ========================= FND LOG =============================
7478
7479 EXIT WHEN g_bc_pkts_hist.count = 0;
7480
7481 FORALL i IN 1..g_bc_pkts_hist.count
7482 insert into gl_bc_packets_hists
7483 values g_bc_pkts_hist(i);
7484
7485 END LOOP; -- Bug 10171221
7486
7487 if p_purge_days > 0 then
7488
7489 DELETE from psa_xla_accounting_errors
7490 where (sysdate - creation_date) >= p_purge_days;
7491
7492 -- =========================== FND LOG ===========================
7493 psa_utils.debug_other_string(g_state_level,l_full_path, ' Delete psa_xla_accounting_errors deleted ' || SQL%ROWCOUNT || ' rows');
7494 -- ========================= FND LOG =============================
7495
7496 DELETE from psa_bc_accounting_errors
7497 where (sysdate - creation_date) >= p_purge_days;
7498
7499 -- =========================== FND LOG ===========================
7500 psa_utils.debug_other_string(g_state_level,l_full_path, ' Delete psa_bc_accounting_errors deleted ' || SQL%ROWCOUNT || ' rows');
7501 -- ========================= FND LOG =============================
7502
7503 DELETE from psa_xla_validation_lines_logs
7504 where (sysdate - creation_date) >= p_purge_days;
7505
7506 -- =========================== FND LOG ===========================
7507 psa_utils.debug_other_string(g_state_level,l_full_path, ' Delete psa_xla_validation_lines_logs deleted ' || SQL%ROWCOUNT || ' rows');
7508 -- ========================= FND LOG =============================
7509
7510 DELETE from psa_xla_events_logs
7511 where (sysdate - creation_date) >= p_purge_days;
7512
7513 -- =========================== FND LOG ===========================
7514 psa_utils.debug_other_string(g_state_level,l_full_path, ' Delete psa_xla_events_logs deleted ' || SQL%ROWCOUNT || ' rows');
7515 -- ========================= FND LOG =============================
7516
7517 DELETE from psa_xla_ae_lines_logs
7518 where (sysdate - creation_date) >= p_purge_days;
7519
7520 -- =========================== FND LOG ===========================
7521 psa_utils.debug_other_string(g_state_level,l_full_path, ' Delete psa_xla_ae_lines_logs deleted ' || SQL%ROWCOUNT || ' rows');
7522 -- ========================= FND LOG =============================
7523
7524 DELETE from psa_xla_ae_headers_logs
7525 where (sysdate - creation_date) >= p_purge_days;
7526
7527 -- =========================== FND LOG ===========================
7528 psa_utils.debug_other_string(g_state_level,l_full_path, ' Delete psa_xla_ae_header_logs deleted ' || SQL%ROWCOUNT || ' rows');
7529 -- ========================= FND LOG =============================
7530
7531 -- ========================= FND LOG =============================
7532
7533 DELETE from psa_xla_dist_links_logs
7534 where (sysdate - creation_date) >= p_purge_days;
7535
7536 -- =========================== FND LOG ===========================
7537 psa_utils.debug_other_string(g_state_level,l_full_path, ' Delete psa_xla_dist_links_logs deleted ' || SQL%ROWCOUNT || ' rows');
7538 -- ========================= FND LOG =============================
7539
7540 end if;
7541
7542 END optimize_packets;
7543
7544
7545 /*=======================================================================+
7546 | Function : BC_OPTIMIZER |
7547 | Description : Invoked by SRS "Budgetary Control Optimizer" |
7548 | Optimize GL_BC_PACKETS DATA |
7549 | Delete unprocessed payables BC events |
7550 | Delete processed orphan payables BC events |
7551 +=======================================================================*/
7552
7553 PROCEDURE bc_optimizer (err_buf OUT NOCOPY VARCHAR2,
7554 ret_code OUT NOCOPY VARCHAR2,
7555 p_ledger_id IN NUMBER,
7556 p_purge_days IN NUMBER,
7557 p_delete_mode IN VARCHAR2) IS
7558
7559 p_init_msg_list varchar2(1);
7560 l_r12_upgrade_date date;
7561 p_calling_sequence varchar2(50);
7562 p_return_status varchar2(2);
7563 p_msg_count number;
7564 p_msg_data varchar2(50);
7565 l_path_name varchar2(500):= 'BC_Optimizer';
7566
7567 l_prepare_stmt VARCHAR2(1024);
7568
7569 BEGIN
7570
7571 psa_utils.debug_other_string(g_state_level,l_path_name,'p_ledger_id = '||p_ledger_id);
7572 psa_utils.debug_other_string(g_state_level,l_path_name,'p_purge_days = '||p_purge_days);
7573 psa_utils.debug_other_string(g_state_level,l_path_name,'p_delete_mode = '||p_delete_mode);
7574 IF (NVL(p_delete_mode, 'B') IN ('B', 'P')) THEN
7575 optimize_packets(p_ledger_id, p_purge_days);
7576 psa_utils.debug_other_string(g_state_level,l_path_name,'Successfully optimized the gl_bc_packets data');
7577 END IF;
7578
7579 IF (NVL(p_delete_mode, 'B') IN ('B', 'E')) THEN
7580 -- R12 upgrade date fetch to delete all unprocessed events from R12 installation date to sysdate
7581 psa_utils.debug_other_string(g_state_level,l_path_name,'Fetch PSA: R12 Upgrade Date profile value');
7582 l_r12_upgrade_date :=to_date( Fnd_Profile.Value_Wnps('PSA_R12_UPGRADE_DATE'), 'MM/DD/YYYY HH24:MI:SS'); -- fetch the profile value
7583
7584 BEGIN
7585 l_prepare_stmt := ' BEGIN '||
7586 ' PO_DRAFT_EVENTS_PKG. delete_draft_events ('||
7587 ' :p_init_msg_list, '||
7588 ' :p_ledger_id, '||
7589 ' :p_start_date, '||
7590 ' :p_end_date, '||
7591 ' :p_calling_sequence, '||
7592 ' :x_return_status, '||
7593 ' :x_msg_count, '||
7594 ' :x_msg_data); '||
7595 ' END; ';
7596
7597 psa_utils.debug_other_string(g_state_level,l_path_name,'l_prepare_stmt='||l_prepare_stmt);
7598 psa_utils.debug_other_string(g_state_level,l_path_name,'Before calling delete_events PO');
7599 EXECUTE IMMEDIATE l_prepare_stmt USING IN 'F',
7600 IN p_ledger_id,
7601 IN l_r12_upgrade_date,
7602 IN SYSDATE,
7603 IN 'psa_funds_cecker_pkg.bc_optimizer',
7604 OUT p_return_status,
7605 OUT p_msg_count,
7606 OUT p_msg_data;
7607 psa_utils.debug_other_string(g_state_level,l_path_name,'After calling delete_events PO');
7608 psa_utils.debug_other_string(g_state_level,l_path_name,'p_return_status='||p_return_status);
7609 IF (p_return_status = Fnd_Api.G_Ret_Sts_Success) THEN
7610 COMMIT;
7611 ELSE
7612 psa_utils.debug_other_string(g_state_level,l_path_name,'p_msg_data='||p_msg_data);
7613 psa_utils.debug_other_string(g_state_level,l_path_name,'p_msg_count='||p_msg_count);
7614 ROLLBACK;
7615 END IF;
7616 EXCEPTION
7617 WHEN OTHERS THEN
7618 psa_utils.debug_other_string(g_state_level,l_path_name,'SQLERROR'||SQLERRM);
7619 END;
7620
7621 BEGIN
7622 psa_utils.debug_other_string(g_state_level,l_path_name,'Before calling delete_events');
7623 PSA_AP_BC_PVT.delete_events(
7624 p_init_msg_list => 'F',
7625 p_ledger_id => p_ledger_id,
7626 p_start_date => l_r12_upgrade_date,
7627 p_end_date => sysdate,
7628 p_calling_sequence => 'psa_funds_cecker_pkg.bc_optimizer',
7629 x_return_status => p_return_status,
7630 x_msg_count =>p_msg_count,
7631 x_msg_data => p_msg_data);
7632 COMMIT;
7633
7634 psa_utils.debug_other_string(g_state_level,l_path_name,'After calling delete_events');
7635 EXCEPTION
7636 WHEN others THEN
7637 psa_utils.debug_other_string(g_state_level,l_path_name,'Inside delete_event exception: '||SQLERRM);
7638 NULL;
7639 END;
7640
7641 BEGIN
7642 psa_utils.debug_other_string(g_state_level,l_path_name,'Before calling delete_processed_orphan_events');
7643 psa_ap_bc_pvt.delete_processed_orphan_events
7644 ( p_init_msg_list => 'F',
7645 p_ledger_id => p_ledger_id,
7646 p_calling_sequence => 'psa_funds_cecker_pkg.bc_optimizer',
7647 p_return_status => p_return_status,
7648 p_msg_count =>p_msg_count,
7649 p_msg_data => p_msg_data);
7650 COMMIT;
7651 psa_utils.debug_other_string(g_state_level,l_path_name,'After calling delete_processed_orphan_events');
7652 EXCEPTION
7653 WHEN others THEN
7654 psa_utils.debug_other_string(g_state_level,l_path_name,'Inside delete_processed_orphan_events exception: '||SQLERRM);
7655 NULL;
7656 END;
7657 END IF;
7658 END bc_optimizer;
7659
7660
7661 /*=======================================================================+
7662 | Function : BC_PURGE_HIST |
7663 | Description : Invoked by SRS "Budgetary Control History Purge" |
7664 | Deletes rows from gl_bc_packets_hists depending upon |
7665 | the criteria selected by user while running SRS |
7666 +=======================================================================*/
7667
7668 PROCEDURE bc_purge_hist (err_buf OUT NOCOPY VARCHAR2,
7669 ret_code OUT NOCOPY VARCHAR2,
7670 p_ledger_id IN NUMBER,
7671 p_purge_mode IN VARCHAR2,
7672 p_purge_statuses IN VARCHAR2,
7673 p_purge_date IN VARCHAR2) IS
7674
7675 l_stmt VARCHAR2(5000);
7676 l_status_code VARCHAR2(50);
7677 l_purge_date DATE;
7678 l_full_path VARCHAR2(100);
7679 BEGIN
7680 l_full_path := g_path||'Bc_Purge_Hist';
7681
7682 optimize_packets(p_ledger_id, 0);
7683
7684 l_purge_date := TO_DATE(p_purge_date, 'YYYY/MM/DD HH24:MI:SS');
7685
7686 -- =========================== FND LOG ===========================
7687 psa_utils.debug_other_string(g_state_level,l_full_path, ' l_purge_date -> ' || TO_CHAR(l_purge_date, 'DD-MON-YYYY HH24:MI:SS'));
7688 -- ========================= FND LOG =============================
7689
7690
7691 l_stmt := 'delete from gl_bc_packets_hists '||
7692 'where (last_update_date < :purge_date) '||
7693 ' and ledger_id = :p_ledger_id ';
7694
7695 l_status_code := CASE p_purge_mode||p_purge_statuses
7696 WHEN 'CP' THEN '''S'''
7697 WHEN 'CF' THEN '''F'''
7698 WHEN 'CE' THEN '''T'''
7699 WHEN 'CA' THEN '''S'', ''F'', ''T'''
7700 WHEN 'RP' THEN '''A'''
7701 WHEN 'RF' THEN '''R'''
7702 WHEN 'RE' THEN '''T'''
7703 WHEN 'RA' THEN '''A'', ''R'', ''T'''
7704 WHEN 'AP' THEN '''S'', ''A'''
7705 WHEN 'AF' THEN '''F'', ''R'''
7706 WHEN 'AE' THEN '''T'''
7707 WHEN 'AA' THEN '''S'', ''F'', ''A'', ''R'', ''T'''
7708 END;
7709
7710 l_stmt := l_stmt ||'and status_code IN ('||l_status_code||')';
7711
7712 -- =========================== FND LOG ===========================
7713 psa_utils.debug_other_string(g_state_level,l_full_path, ' l_stmt -> ' || l_stmt);
7714 -- ========================= FND LOG =============================
7715
7716
7717 execute immediate l_stmt using l_purge_date, p_ledger_id;
7718
7719 commit;
7720
7721 END bc_purge_hist;
7722
7723 /*=======================================================================+
7724 | Function : GET_PACKET_ID |
7725 | Description : Returns the next packet_id using gl_bc_packets_s seq |
7726 +=======================================================================*/
7727
7728 FUNCTION get_packet_id RETURN NUMBER IS
7729 l_pkt_id gl_bc_packets.packet_id%type;
7730 l_full_path VARCHAR2(100);
7731 BEGIN
7732
7733 l_full_path := g_path||'Get_Packet_Id';
7734
7735 select gl_bc_packets_s.nextval into l_pkt_id
7736 from dual;
7737
7738 -- =========================== FND LOG ===========================
7739 psa_utils.debug_other_string(g_state_level,l_full_path, ' l_pkt_id -> ' || l_pkt_id);
7740 -- ========================= FND LOG =============================
7741
7742 return l_pkt_id;
7743 END get_packet_id;
7744
7745 /*=======================================================================+
7746 | Function : POPULATE_BC_PKTS |
7747 | Description : Inserts data in gl_bc_packets using the plsql table |
7748 | passed as parameter. Commits in autonomous mode. |
7749 +=======================================================================*/
7750
7751 FUNCTION populate_bc_pkts (p_bc_pkts IN BC_PKTS_REC) RETURN BOOLEAN IS
7752
7753 -- ========================= FND LOG ===========================
7754 l_full_path VARCHAR2(100);
7755 -- ========================= FND LOG ===========================
7756 pragma autonomous_transaction;
7757
7758 BEGIN
7759
7760 l_full_path := g_path||'Populate_Bc_pkts';
7761
7762 -- Now that plsql table is populated, insert data in gl_bc_packets.
7763
7764 FORALL i IN 1..p_bc_pkts.count
7765 INSERT INTO gl_bc_packets
7766 VALUES p_bc_pkts(i);
7767
7768 commit;
7769
7770 RETURN TRUE;
7771
7772 EXCEPTION
7773 WHEN OTHERS THEN
7774 psa_utils.debug_other_string(g_excep_level,l_full_path, ' BCTRL -> '||sqlerrm);
7775 rollback;
7776 RETURN FALSE;
7777
7778 END populate_bc_pkts;
7779
7780
7781 /*=======================================================================+
7782 | Procedure : GLXFMA |
7783 | Description : Invoked by Concurrent Program for Mass Funds Check, |
7784 | Reserve etc. Upgraded from 11i. |
7785 +=======================================================================*/
7786 PROCEDURE glxfma ( err_buf OUT NOCOPY VARCHAR2,
7787 ret_code OUT NOCOPY VARCHAR2,
7788 p_ledger_id IN NUMBER,
7789 p_check_flag IN VARCHAR2,
7790 p_autopost_set_id IN NUMBER) IS
7791 CURSOR sel1 is
7792
7793 SELECT
7794 B.actual_flag,
7795 H.je_source,
7796 B.default_period_name,
7797 B.je_batch_id,
7798 substrb(B.name,1,88)
7799 FROM
7800 gl_je_headers H,
7801 gl_je_batches B,
7802 gl_automatic_posting_options O,
7803 gl_automatic_posting_sets S
7804 WHERE
7805 S.autopost_set_id = p_autopost_set_id
7806 AND S.autopost_set_id = O.autopost_set_id
7807 AND o.ledger_id = H.ledger_id
7808 AND B.actual_flag = decode(O.actual_flag,
7809 'L', B.actual_flag,
7810 O.actual_flag)
7811 AND B.default_period_name = decode(O.period_name,
7812 'ALL', B.default_period_name,
7813 O.period_name)
7814 AND B.je_batch_id = H.je_batch_id
7815 AND H.je_source = decode(O.je_source_name,
7816 'ALL', H.je_source,
7817 O.je_source_name)
7818 AND B.status = 'U'
7819 AND B.budgetary_control_status in ('R', 'F')
7820 AND NOT EXISTS
7821 ( SELECT 'Not all category match'
7822 FROM GL_JE_HEADERS H2
7823 WHERE
7824 H2.je_batch_id = B.je_batch_id
7825 AND H2.je_category <> decode(O.je_category_name,
7826 'ALL', H2.je_category,
7827 O.je_category_name) )
7828 AND NOT EXISTS
7829 ( SELECT 'Untaxed Journals'
7830 FROM GL_JE_HEADERS GLH
7831 WHERE GLH.tax_status_code = 'R'
7832 AND GLH.je_batch_id = B.je_batch_id
7833 AND B.actual_flag = 'A'
7834 AND GLH.currency_code <> 'STAT'
7835 AND GLH.je_source = 'Manual' )
7836 GROUP BY B.je_batch_id, B.actual_flag,
7837 B.default_period_name,B.name,H.je_source
7838 ORDER BY B.default_period_name,B.actual_flag;
7839
7840 CURSOR sel2 is
7841
7842 SELECT
7843 b.actual_flag,
7844 h.je_source,
7845 b.default_period_name,
7846 b.je_batch_id,
7847 substrb(b.name,1,88)
7848 FROM
7849 gl_je_headers h,
7850 gl_je_batches b,
7851 gl_automatic_posting_options o,
7852 gl_automatic_posting_sets s
7853 WHERE
7854 s.autopost_set_id = p_autopost_set_id
7855 AND s.autopost_set_id = o.autopost_set_id
7856 AND o.ledger_id = H.ledger_id
7857 AND b.actual_flag = decode(o.actual_flag,
7858 'L', b.actual_flag,
7859 o.actual_flag)
7860 AND b.default_period_name = decode(o.period_name,
7861 'ALL', b.default_period_name,
7862 o.period_name)
7863 AND b.je_batch_id = h.je_batch_id
7864 AND h.je_source = decode(o.je_source_name,
7865 'ALL', h.je_source,
7866 o.je_source_name)
7867 AND b.status = 'U'
7868 AND b.budgetary_control_status in ('R', 'F')
7869 AND NOT EXISTS
7870 ( SELECT 'Not all category match'
7871 FROM gl_je_headers h2
7872 WHERE
7873 h2.je_batch_id = b.je_batch_id
7874 AND h2.je_category <> decode(o.je_category_name,
7875 'ALL', h2.je_category,
7876 o.je_category_name) )
7877 GROUP BY b.je_batch_id, b.actual_flag,
7878 b.default_period_name,b.name,h.je_source
7879 ORDER BY b.default_period_name,b.actual_flag;
7880
7881 CURSOR c_seg_info (p_ledger_id NUMBER) IS
7882
7883 SELECT
7884 application_column_name
7885 FROM
7886 fnd_id_flex_segments
7887 WHERE
7888 id_flex_num = (SELECT
7889 chart_of_accounts_id
7890 FROM gl_ledgers
7891 WHERE ledger_id = p_ledger_id)
7892 AND id_flex_code = 'GL#'
7893 AND application_id = 101
7894 AND enabled_flag = 'Y';
7895
7896 TYPE je_ref_cursor IS REF CURSOR;
7897 l_je_lines je_ref_cursor;
7898 l_je_sum_lines je_ref_cursor;
7899 l_je_bud_lines je_ref_cursor;
7900
7901 l_full_path VARCHAR2(100);
7902 l_bc_pkts bc_pkts_rec;
7903 l_bc_pkts_cnt number;
7904 l_tmp_bc_pkts bc_pkts_rec;
7905 l_failed_bc_pkts bc_pkts_rec;
7906 l_failed_bc_pkts_cnt number;
7907 l_sob_name gl_sets_of_books.name%TYPE;
7908 l_budgetary_control_flag gl_sets_of_books.enable_budgetary_control_flag%TYPE;
7909 l_automatic_tax_flag gl_sets_of_books.enable_automatic_tax_flag%TYPE;
7910 l_coa_id gl_sets_of_books.chart_of_accounts_id%TYPE;
7911 l_currency_code gl_sets_of_books.currency_code%TYPE;
7912 l_autopost_set_name gl_automatic_posting_sets.autopost_set_name%TYPE;
7913 l_appl_id fnd_application.application_id%TYPE;
7914 l_resp_id fnd_responsibility.responsibility_id%TYPE;
7915 l_user_id fnd_user.user_id%TYPE;
7916 l_actual_flag gl_je_batches.actual_flag%TYPE;
7917 l_source_name gl_je_headers.je_source%TYPE;
7918 l_period_name gl_je_batches.default_period_name%TYPE;
7919 l_je_batch_id gl_je_batches.je_batch_id%TYPE;
7920 l_batch_name gl_je_batches.name%TYPE;
7921 l_packet_id gl_bc_packets.packet_id%TYPE;
7922 l_main_stmt varchar2(4000);
7923 l_tmp_stmt varchar2(4000);
7924 l_action_stmt varchar2(4000);
7925 l_je_stmt varchar2(4000);
7926 l_bc_not_enabled_msg varchar2(250);
7927 l_msg2 varchar2(250);
7928 l_check_flag varchar2(10);
7929 l_glxfck_return_status boolean;
7930 l_glxfck_return_code varchar2(10);
7931 l_calling_prog_flag varchar2(10);
7932 l_fmeaning varchar2(50);
7933 l_jmeaning varchar2(50);
7934 l_date varchar2(50);
7935 l_header boolean;
7936 l_je_first boolean;
7937 l_ledger_id gl_automatic_posting_options.ledger_id%TYPE;
7938 l_session_id gl_bc_packets.session_id%type;
7939 l_serial_id gl_bc_packets.serial_id%type;
7940 l_seg_ccid varchar2(200);
7941 l_je_header_name gl_je_headers.name%TYPE;
7942 l_je_header_id gl_je_headers.je_header_id%TYPE;
7943 l_je_line_num gl_je_lines.je_line_num%TYPE;
7944 l_entered_dr gl_je_lines.entered_dr%TYPE;
7945 l_entered_cr gl_je_lines.entered_cr%TYPE;
7946 l_line_description gl_lookups.description%TYPE;
7947 l_line_result_code gl_bc_packets.result_code%TYPE;
7948 l_ccid gl_je_lines.code_combination_id%TYPE;
7949 l_rowid varchar2(100);
7950 l_priority gl_lookups.meaning%TYPE;
7951 l_je_seg_stmt varchar2(4000);
7952 l_je_sum_flex varchar2(4000);
7953 l_je_bud_stmt varchar2(4000);
7954 l_je_bud_flex varchar2(4000);
7955 l_je_bud_dr gl_bc_packets.entered_dr%TYPE;
7956 l_je_bud_cr gl_bc_packets.entered_cr%TYPE;
7957 l_je_bud_result_code gl_bc_packets.result_code%TYPE;
7958 l_je_bud_desc gl_lookups.description%TYPE;
7959 l_je_bud_ccid gl_code_combinations.code_combination_id%TYPE;
7960 l_ussgl_parent_id gl_bc_packets.ussgl_parent_id%TYPE;
7961 l_je_bud_seg_stmt varchar2(4000);
7962 l_je_bud_sum_flex varchar2(4000);
7963
7964 -- XML variables
7965 l_xml_b_header boolean;
7966 l_application_name varchar2(300);
7967 l_report_name varchar2(300);
7968 l_funds_action varchar2(300);
7969 l_failure_warning varchar2(500);
7970 l_xml_je_lines_header boolean;
7971 l_xml_f_b_header boolean;
7972 l_xml_f_l_header boolean;
7973 l_xml_f_sum_header boolean;
7974 l_xml_f_bud_header boolean;
7975 l_xml_f_bud_sum_header boolean;
7976
7977 BEGIN
7978
7979 l_full_path := g_path || 'glxfma';
7980 l_check_flag := p_check_flag;
7981 l_ledger_id := p_ledger_id;
7982
7983 --Get the Application Name
7984 FND_MESSAGE.SET_NAME('PSA', 'R_FCMA0031');
7985 l_application_name := FND_MESSAGE.GET();
7986
7987 --Get the Report Name
7988 FND_MESSAGE.SET_NAME('PSA', 'R_FCMA0030');
7989 l_report_name := FND_MESSAGE.GET();
7990
7991 --Get the Funds Action
7992 IF (l_check_flag = 'C' OR l_check_flag = 'M') THEN
7993 FND_MESSAGE.SET_NAME('PSA', 'R_FCMA0032');
7994 ELSIF (l_check_flag = 'R' OR l_check_flag = 'P') THEN
7995 FND_MESSAGE.SET_NAME('PSA', 'R_FCMA0033');
7996 ELSE
7997 FND_MESSAGE.SET_NAME('PSA', 'R_FCMA0032');
7998 END IF;
7999 l_funds_action := FND_MESSAGE.GET();
8000
8001 --Get the Failure/Warning message
8002 IF (l_check_flag = 'C' OR l_check_flag = 'M') THEN
8003 FND_MESSAGE.SET_NAME('PSA', 'R_FCMA0035');
8004 ELSIF (l_check_flag = 'R' OR l_check_flag = 'P') THEN
8005 FND_MESSAGE.SET_NAME('PSA', 'R_FCMA0036');
8006 ELSE
8007 FND_MESSAGE.SET_NAME('PSA', 'R_FCMA0035');
8008 END IF;
8009 l_failure_warning := FND_MESSAGE.GET();
8010
8011 --Picking the date from the database
8012 SELECT
8013 TO_CHAR(SYSDATE, 'DD-MON-YY HH24:MI')
8014 INTO
8015 l_date
8016 FROM
8017 dual;
8018
8019 --The xml reporting variables.
8020 l_header := true;
8021 l_xml_f_b_header := true;
8022 l_xml_f_l_header := true;
8023 l_xml_je_lines_header := true;
8024 l_xml_b_header := true;
8025 l_xml_f_sum_header := true;
8026 l_xml_f_bud_header := true;
8027 l_xml_f_bud_sum_header := true;
8028
8029 --Start of xml report output
8030 -- =========================== XML OUT =============================
8031 fnd_file.put_line(fnd_file.output, '<?xml version = ''1.0'' encoding = ''ISO-8859-1''?>');
8032 fnd_file.put_line(fnd_file.output, '<REPORT_ROOT>');
8033 fnd_file.put_line(fnd_file.output, ' <PARAMETERS>');
8034 fnd_file.put_line(fnd_file.output, ' <APPLICATION_NAME>'||l_application_name||'</APPLICATION_NAME>');
8035 fnd_file.put_line(fnd_file.output, ' <REPORT_NAME>'||l_report_name||'</REPORT_NAME>');
8036 fnd_file.put_line(fnd_file.output, ' <DATE>'||l_date||'</DATE>');
8037 fnd_file.put_line(fnd_file.output, ' <FUNDS_ACTION>'||l_funds_action||'</FUNDS_ACTION>');
8038 fnd_file.put_line(fnd_file.output, ' </PARAMETERS>');
8039 -- =========================== XML OUT =============================
8040
8041 BEGIN
8042 SELECT
8043 name,
8044 enable_budgetary_control_flag,
8045 enable_automatic_tax_flag,
8046 chart_of_accounts_id,
8047 currency_code
8048 INTO
8049 l_sob_name,
8050 l_budgetary_control_flag,
8051 l_automatic_tax_flag,
8052 l_coa_id,
8053 l_currency_code
8054 FROM
8055 gl_sets_of_books
8056 WHERE
8057 set_of_books_id = p_ledger_id;
8058 EXCEPTION
8059 WHEN OTHERS THEN
8060 -- =========================== FND LOG ===========================
8061 fnd_file.put_line(fnd_file.log, 'Funds C/R: Failed to fetch data from gl_sets_of_books');
8062 psa_utils.debug_other_string(g_excep_level,l_full_path,
8063 'Funds C/R: Failed to fetch data from gl_sets_of_books');
8064 -- ========================= FND LOG =============================
8065 END;
8066
8067 -- =========================== FND LOG ===========================
8068 fnd_file.put_line(fnd_file.log, 'Funds C/R: l_sob_name -> '||l_sob_name);
8069 fnd_file.put_line(fnd_file.log, 'Funds C/R: l_budgetary_control_flag -> '||l_budgetary_control_flag);
8070 fnd_file.put_line(fnd_file.log, 'Funds C/R: l_automatic_tax_flag -> '||l_automatic_tax_flag);
8071 fnd_file.put_line(fnd_file.log, 'Funds C/R: l_coa_id -> '||l_coa_id);
8072 fnd_file.put_line(fnd_file.log, 'Funds C/R: l_currency_code -> '||l_currency_code);
8073 fnd_file.put_line(fnd_file.log, 'Funds C/R: l_check_flag -> '||l_check_flag);
8074 psa_utils.debug_other_string(g_state_level, l_full_path, 'Funds C/R: l_sob_name -> '||l_sob_name);
8075 psa_utils.debug_other_string(g_state_level, l_full_path, 'Funds C/R: l_budgetary_control_flag -> '||l_budgetary_control_flag);
8076 psa_utils.debug_other_string(g_state_level, l_full_path, 'Funds C/R: l_automatic_tax_flag -> '||l_automatic_tax_flag);
8077 psa_utils.debug_other_string(g_state_level, l_full_path, 'Funds C/R: l_coa_id -> '||l_coa_id);
8078 psa_utils.debug_other_string(g_state_level, l_full_path, 'Funds C/R: l_currency_code -> '||l_currency_code);
8079 psa_utils.debug_other_string(g_state_level, l_full_path, 'Funds C/R: l_check_flag -> '||l_check_flag);
8080 -- =========================== FND LOG =============================
8081
8082 IF (l_budgetary_control_flag = 'N') THEN
8083 FND_MESSAGE.SET_NAME('PSA', 'R_FCMA0037');
8084 l_bc_not_enabled_msg := FND_MESSAGE.GET();
8085 -- =========================== FND LOG ===========================
8086 psa_utils.debug_other_string(g_state_level, l_full_path,
8087 'Funds C/R: l_budgetary_control_flag -> '||l_budgetary_control_flag); --Need to finalize the debug level
8088 fnd_file.put_line(fnd_file.log, 'Funds C/R: '||l_bc_not_enabled_msg);
8089 -- ========================= FND LOG =============================
8090
8091 -- =========================== XML OUT =============================
8092 fnd_file.put_line(fnd_file.output, '<BC_NOT_ENABLED>'||l_bc_not_enabled_msg||'</BC_NOT_ENABLED>');
8093 -- =========================== XML OUT =============================
8094 GOTO normal_exit;
8095 END IF;
8096
8097 BEGIN
8098 SELECT
8099 autopost_set_name
8100 INTO
8101 l_autopost_set_name
8102 FROM
8103 gl_automatic_posting_sets
8104 WHERE
8105 autopost_set_id = p_autopost_set_id;
8106 EXCEPTION
8107 WHEN OTHERS THEN
8108 -- =========================== FND LOG ===========================
8109 psa_utils.debug_other_string(g_excep_level,l_full_path,
8110 'Funds C/R: Failed to fetch autopost_set_name from gl_automatic_posting_sets');
8111 fnd_file.put_line(fnd_file.log, 'Funds C/R: Failed to fetch autopost_set_name from gl_automatic_posting_sets');
8112 -- ========================= FND LOG =============================
8113 END;
8114
8115 l_appl_id := 101;
8116 l_resp_id := FND_GLOBAL.resp_id;
8117 l_user_id := FND_GLOBAL.user_id;
8118
8119 -- =========================== FND LOG ===========================
8120 fnd_file.put_line(fnd_file.log, 'Funds C/R: p_autopost_set_id -> '||p_autopost_set_id);
8121 fnd_file.put_line(fnd_file.log, 'Funds C/R: l_autopost_set_name -> '||l_autopost_set_name);
8122 fnd_file.put_line(fnd_file.log, 'Funds C/R: l_appl_id -> '||l_appl_id);
8123 fnd_file.put_line(fnd_file.log, 'Funds C/R: l_resp_id -> '||l_resp_id);
8124 fnd_file.put_line(fnd_file.log, 'Funds C/R: l_user_id -> '||l_user_id);
8125 psa_utils.debug_other_string(g_state_level, l_full_path, 'Funds C/R: p_autopost_set_id -> '||p_autopost_set_id);
8126 psa_utils.debug_other_string(g_state_level, l_full_path, 'Funds C/R: l_autopost_set_name -> '||l_autopost_set_name);
8127 psa_utils.debug_other_string(g_state_level, l_full_path, 'Funds C/R: l_appl_id -> '||l_appl_id);
8128 psa_utils.debug_other_string(g_state_level, l_full_path, 'Funds C/R: l_resp_id -> '||l_resp_id);
8129 psa_utils.debug_other_string(g_state_level, l_full_path, 'Funds C/R: l_user_id -> '||l_user_id);
8130 -- =========================== FND LOG =============================
8131
8132 IF (l_automatic_tax_flag = 'Y') AND (p_check_flag = 'R') THEN
8133
8134 OPEN sel1;
8135 ELSE
8136 OPEN sel2;
8137
8138 END IF;
8139
8140 l_bc_pkts := bc_pkts_rec();
8141 l_bc_pkts_cnt := 0;
8142 l_failed_bc_pkts := bc_pkts_rec();
8143 l_failed_bc_pkts_cnt := 0;
8144
8145 LOOP
8146 IF sel1%ISOPEN THEN
8147
8148 FETCH
8149 sel1
8150 INTO
8151 l_actual_flag,
8152 l_source_name,
8153 l_period_name,
8154 l_je_batch_id,
8155 l_batch_name;
8156
8157 EXIT WHEN sel1%NOTFOUND;
8158
8159 ELSIF sel2%ISOPEN THEN
8160
8161 FETCH
8162 sel2
8163 INTO
8164 l_actual_flag,
8165 l_source_name,
8166 l_period_name,
8167 l_je_batch_id,
8168 l_batch_name;
8169
8170 EXIT WHEN sel2%NOTFOUND;
8171
8172 END IF;
8173
8174 l_packet_id := get_packet_id;
8175
8176 -- =========================== FND LOG ===========================
8177 fnd_file.put_line(fnd_file.log, 'Funds C/R: -------------------------------');
8178 fnd_file.put_line(fnd_file.log, 'Funds C/R: l_period_name -> '||l_period_name);
8179 fnd_file.put_line(fnd_file.log, 'Funds C/R: l_actual_flag -> '||l_actual_flag);
8180 fnd_file.put_line(fnd_file.log, 'Funds C/R: l_je_batch_id -> '||l_je_batch_id);
8181 fnd_file.put_line(fnd_file.log, 'Funds C/R: l_packet_id -> '||l_packet_id);
8182 fnd_file.put_line(fnd_file.log, 'Funds C/R: l_batch_name -> '||l_batch_name);
8183 fnd_file.put_line(fnd_file.log, 'Funds C/R: l_source_name -> '||l_source_name);
8184 psa_utils.debug_other_string(g_state_level, l_full_path, 'Funds C/R: -------------------------------');
8185 psa_utils.debug_other_string(g_state_level, l_full_path, 'Funds C/R: l_period_name -> '||l_period_name);
8186 psa_utils.debug_other_string(g_state_level, l_full_path, 'Funds C/R: l_actual_flag -> '||l_actual_flag);
8187 psa_utils.debug_other_string(g_state_level, l_full_path, 'Funds C/R: l_je_batch_id -> '||l_je_batch_id);
8188 psa_utils.debug_other_string(g_state_level, l_full_path, 'Funds C/R: l_packet_id -> '||l_packet_id);
8189 psa_utils.debug_other_string(g_state_level, l_full_path, 'Funds C/R: l_batch_name -> '||l_batch_name);
8190 psa_utils.debug_other_string(g_state_level, l_full_path, 'Funds C/R: l_source_name -> '||l_source_name);
8191 -- =========================== FND LOG =============================
8192
8193 -- =========================== XML OUT =============================
8194 IF (l_xml_b_header <> FALSE) THEN
8195 fnd_file.put_line(fnd_file.output, ' <LIST_G_JE_BATCH_NAME>');
8196 l_xml_b_header := FALSE;
8197 END IF;
8198 -- =========================== XML OUT =============================
8199
8200
8201 -- Get the session_id and serial# for the current session
8202 -- These columns will then be inserted in gl_bc_packets.
8203
8204 -- ====== FND LOG ======
8205 psa_utils.debug_other_string(g_state_level,l_full_path, ' BCTRL -> Invoking get_session_details() ');
8206 -- ====== FND LOG ======
8207
8208 get_session_details(l_session_id, l_serial_id);
8209
8210 -- ====== FND LOG ======
8211 psa_utils.debug_other_string(g_state_level,l_full_path, ' BCTRL -> Session_Id = '||l_session_id);
8212 psa_utils.debug_other_string(g_state_level,l_full_path, ' BCTRL -> Serial_Id = '||l_serial_id);
8213 -- ====== FND LOG ======
8214
8215 l_main_stmt := '';
8216
8217 -- =========================== FND LOG ===========================
8218 fnd_file.put_line(fnd_file.log, 'Funds C/R: l_main_stmt -> '||l_main_stmt);
8219 psa_utils.debug_other_string(g_state_level,l_full_path, 'Funds C/R: l_main_stmt -> '||l_main_stmt);
8220 -- =========================== FND LOG =============================
8221
8222 l_tmp_stmt := 'SELECT '||
8223 l_packet_id||', '||
8224 l_ledger_id||', '||''''||
8225 l_source_name||''''||
8226 ', h.je_category'||
8227 ', l.code_combination_id, '||''''||
8228 l_actual_flag|| ''''||
8229 ', ps.period_name, ps.period_year, ps.period_num, ps.quarter_num, '||
8230 'h.currency_code, decode('||''''||l_check_flag||''''||',''C'',''C'',''M'',''C'',''P'',''P'',''R'',''P''), sysdate, '||
8231 l_user_id;
8232
8233 l_action_stmt:= CASE l_actual_flag
8234 WHEN 'B' THEN ', h.budget_version_id, NULL, NULL'
8235 WHEN 'E' THEN ', NULL, h.encumbrance_type_id, NULL'
8236 WHEN 'A' THEN ', NULL, NULL, NULL'
8237 END;
8238 l_tmp_stmt := l_tmp_stmt || l_action_stmt;
8239
8240 l_tmp_stmt := l_tmp_stmt || ', nvl(l.entered_dr, 0), nvl(l.entered_cr, 0), nvl(l.accounted_dr, 0), nvl(l.accounted_cr, 0), '||
8241 'l.ussgl_transaction_code, '||
8242 'NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '||
8243 'NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '||
8244 'NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '||''''||
8245 l_batch_name||''''||', '||
8246 l_je_batch_id||
8247 ', l.je_header_id, l.je_line_num, '||
8248 'NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '||
8249 'NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '||
8250 'NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '||
8251 l_session_id||', '||l_serial_id||', '||l_appl_id||', '||
8252 'NULL, NULL';
8253
8254 -- =========================== FND LOG ===========================
8255 fnd_file.put_line(fnd_file.log, 'Funds C/R: l_tmp_stmt -> '||l_tmp_stmt);
8256 psa_utils.debug_other_string(g_state_level, l_full_path, 'Funds C/R: l_tmp_stmt -> '||l_tmp_stmt);
8257 -- =========================== FND LOG =============================
8258
8259 l_tmp_stmt := l_tmp_stmt || ' FROM gl_je_lines l, gl_je_headers h, ';
8260
8261 IF (l_actual_flag = 'B') THEN
8262 l_tmp_stmt := l_tmp_stmt || 'gl_budget_versions bv, ';
8263 END IF;
8264
8265 l_tmp_stmt := l_tmp_stmt || ' gl_period_statuses ps WHERE ps.application_id = '||l_appl_id||
8266 ' AND ps.ledger_id = '||l_ledger_id ||
8267 ' AND ps.period_name = '||''''||l_period_name||''''||' AND h.je_batch_id = '||l_je_batch_id ||
8268 ' AND l.je_header_id = h.je_header_id';
8269
8270 l_action_stmt:= CASE l_actual_flag
8271 WHEN 'B' THEN ' AND h.budget_version_id = bv.budget_version_id AND bv.status = ''O'''
8272 WHEN 'E' THEN ' AND (ps.closing_status = ''O'' OR ps.closing_status = ''F'')'
8273 WHEN 'A' THEN ''
8274 END;
8275
8276 l_tmp_stmt := l_tmp_stmt || l_action_stmt;
8277
8278 -- =========================== FND LOG ===========================
8279 fnd_file.put_line(fnd_file.log, 'Funds C/R: l_tmp_stmt -> '||l_tmp_stmt);
8280 psa_utils.debug_other_string(g_state_level, l_full_path, 'Funds C/R: l_tmp_stmt -> '||l_tmp_stmt);
8281 -- =========================== FND LOG =============================
8282
8283 l_main_stmt := l_main_stmt || l_tmp_stmt;
8284
8285 -- =========================== FND LOG ===========================
8286 fnd_file.put_line(fnd_file.log, 'Funds C/R: l_main_stmt -> '||l_main_stmt);
8287 fnd_file.put_line(fnd_file.log, 'Funds C/R: Executing l_main_stmt -> '||l_main_stmt||' using EXECUTE IMMEDIATE');
8288 psa_utils.debug_other_string(g_state_level, l_full_path, 'Funds C/R: l_main_stmt -> '||l_main_stmt);
8289 psa_utils.debug_other_string(g_state_level, l_full_path,
8290 'Funds C/R: Executing l_main_stmt -> '||l_main_stmt||' using EXECUTE IMMEDIATE');
8291 -- =========================== FND LOG =============================
8292
8293 EXECUTE IMMEDIATE l_main_stmt BULK COLLECT INTO l_tmp_bc_pkts;
8294
8295 l_bc_pkts.extend(l_tmp_bc_pkts.count);
8296
8297 FOR x in 1..l_tmp_bc_pkts.count
8298 LOOP
8299 l_bc_pkts_cnt := l_bc_pkts_cnt + 1;
8300 l_bc_pkts(l_bc_pkts_cnt) := l_tmp_bc_pkts(x);
8301
8302 END LOOP;
8303
8304 END LOOP; --End of loop for all the batches
8305
8306 IF NOT populate_bc_pkts (l_bc_pkts) THEN
8307 -- ====== FND LOG ======
8308 psa_utils.debug_other_string(g_error_level,l_full_path, 'Funds C/R: BCTRL -> populate_bc_pkts() failed. ');
8309 psa_utils.debug_other_string(g_error_level,l_full_path, 'Funds C/R: BCTRL -> ERROR: FATAL. ');
8310 -- ====== FND LOG ======
8311 END IF;
8312
8313 -- Invoke funds checker per packet_id
8314
8315 -- ====== FND LOG ======
8316 fnd_file.put_line(fnd_file.log, 'Funds C/R: BCTRL -> Invoking glxfck() per packet.');
8317 psa_utils.debug_other_string(g_state_level,l_full_path, 'Funds C/R: BCTRL -> Invoking glxfck() per packet.');
8318 -- ====== FND LOG ======
8319
8320 FOR x in 1..l_bc_pkts.count
8321 LOOP
8322 IF (x = 1 OR (l_bc_pkts(x).packet_id <> l_bc_pkts(x-1).packet_id)) THEN
8323
8324 -- ====== FND LOG ======
8325 fnd_file.put_line(fnd_file.log, 'Funds C/R: BCTRL -> Invoking glxfck() for packet_id '||l_bc_pkts(x).packet_id);
8326 psa_utils.debug_other_string(g_state_level,l_full_path,
8327 'Funds C/R: BCTRL -> Invoking glxfck() for packet_id '||l_bc_pkts(x).packet_id);
8328 -- ====== FND LOG ======
8329
8330 IF NOT glxfck(p_ledgerid => l_ledger_id,
8331 p_packetid => l_bc_pkts(x).packet_id,
8332 p_mode => l_check_flag,
8333 p_override => 'N',
8334 p_conc_flag => 'Y',
8335 p_user_id => l_user_id,
8336 p_user_resp_id => l_resp_id,
8337 p_calling_prog_flag => 'G',
8338 p_return_code => l_glxfck_return_code) THEN
8339 -- ====== FND LOG ======
8340 fnd_file.put_line(fnd_file.log, 'Funds C/R: BCTRL -> glxfck() failed ');
8341 psa_utils.debug_other_string(g_error_level,l_full_path, 'Funds C/R: BCTRL -> glxfck() failed ');
8342 -- ====== FND LOG ======
8343
8344 -- ============================== FND LOG =========================
8345 fnd_file.put_line(fnd_file.log, 'Funds C/R: BCTRL l_glxfck_return_code -> T ');
8346 psa_utils.debug_other_string(g_state_level,l_full_path, 'Funds C/R: BCTRL l_glxfck_return_code -> T ');
8347 -- ============================== FND LOG =========================
8348
8349 l_glxfck_return_code := 'T';
8350
8351 END IF;
8352
8353
8354 -- If the return code for this packet is Advisory, Failure, Partial,
8355 -- Fatal, we insert into failed packets table type.
8356 IF (l_glxfck_return_code <> 'S') THEN
8357
8358 -- ============================== FND LOG =========================
8359 fnd_file.put_line(fnd_file.log, 'Funds C/R: l_glxfck_return_code ->'||l_glxfck_return_code);
8360 fnd_file.put_line(fnd_file.log, 'Funds C/R: Inserting into l_failed_bc_pkts for packet_id->'||l_bc_pkts(x).packet_id);
8361 psa_utils.debug_other_string(g_state_level,l_full_path,
8362 'Funds C/R: l_glxfck_return_code ->'||l_glxfck_return_code);
8363 psa_utils.debug_other_string(g_state_level,l_full_path,
8364 'Funds C/R: Inserting into l_failed_bc_pkts for packet_id->'||l_bc_pkts(x).packet_id);
8365 -- ============================== FND LOG =========================
8366
8367 l_failed_bc_pkts.extend(1);
8368 l_failed_bc_pkts_cnt := l_failed_bc_pkts_cnt + 1;
8369 l_failed_bc_pkts(l_failed_bc_pkts_cnt) := l_bc_pkts(x);
8370
8371 END IF;
8372
8373 -- =========================== FND LOG ===========================
8374 fnd_file.put_line(fnd_file.log, 'Funds C/R: l_glxfck_return_code -> '||l_glxfck_return_code);
8375 psa_utils.debug_other_string(g_state_level,l_full_path, 'Funds C/R: l_glxfck_return_code -> '||l_glxfck_return_code);
8376 -- =========================== FND LOG =============================
8377 BEGIN
8378 UPDATE
8379 gl_je_batches
8380 SET
8381 budgetary_control_status = decode(l_check_flag, 'R',
8382 decode (l_glxfck_return_code,
8383 'S', 'P',
8384 'A', 'P',
8385 'F', 'F',
8386 'P', 'F',
8387 'T', 'R', l_glxfck_return_code),
8388 'P',
8389 decode (l_glxfck_return_code,
8390 'S', 'P',
8391 'A', 'P',
8392 'F', 'F',
8393 'P', 'F',
8394 'T', 'R', l_glxfck_return_code),
8395 budgetary_control_status),
8396 packet_id = l_bc_pkts(x).packet_id
8397 WHERE
8398 je_batch_id = l_bc_pkts(x).je_batch_id;
8399 EXCEPTION
8400 WHEN OTHERS THEN
8401 -- =========================== FND LOG ===========================
8402 psa_utils.debug_other_string(g_excep_level,l_full_path,
8403 'Funds C/R: Failed to update budgetary_control_status for gl_je_batches');
8404 fnd_file.put_line(fnd_file.log,
8405 'Funds C/R: Failed to update budgetary_control_status for gl_je_batches');
8406 -- ========================= FND LOG =============================
8407 END;
8408
8409 BEGIN
8410 SELECT
8411 meaning
8412 INTO
8413 l_fmeaning
8414 FROM
8415 gl_lookups
8416 WHERE
8417 lookup_code = l_glxfck_return_code
8418 AND lookup_type = 'FUNDS_CHECK_RETURN_CODE';
8419 EXCEPTION
8420 WHEN OTHERS THEN
8421 -- =========================== FND LOG ===========================
8422 psa_utils.debug_other_string(g_excep_level,l_full_path,
8423 'Funds C/R: Failed to fetch meaning from gl_lookups');
8424 fnd_file.put_line(fnd_file.log,
8425 'Funds C/R: Failed to fetch meaning from gl_lookups');
8426 -- ========================= FND LOG =============================
8427 END;
8428
8429 -- =========================== FND LOG ===========================
8430 fnd_file.put_line(fnd_file.log, 'Funds C/R: Return Code F Meaning l_fmeaning -> '||l_fmeaning);
8431 psa_utils.debug_other_string(g_state_level,l_full_path, 'Funds C/R: Return Code F Meaning l_fmeaning -> '||l_fmeaning);
8432 -- =========================== FND LOG =============================
8433
8434 BEGIN
8435 SELECT
8436 l.meaning
8437 INTO
8438 l_jmeaning
8439 FROM
8440 gl_lookups l, gl_je_batches b
8441 WHERE
8442 l.lookup_code = b.budgetary_control_status
8443 AND l.lookup_type = 'JE_BATCH_BC_STATUS'
8444 AND b.je_batch_id = l_bc_pkts(x).je_batch_id;
8445
8446 EXCEPTION
8447 WHEN OTHERS THEN
8448 -- =========================== FND LOG ===========================
8449 psa_utils.debug_other_string(g_excep_level,l_full_path,
8450 'Funds C/R: Failed to fetch meaning from gl_je_batches');
8451 fnd_file.put_line(fnd_file.log,
8452 'Funds C/R: Failed to fetch meaning from gl_be_batches');
8453 -- ========================= FND LOG =============================
8454 END;
8455
8456 -- =========================== FND LOG ===========================
8457 fnd_file.put_line(fnd_file.log, 'Funds C/R: Return Code J Meaning l_jmeaning -> '||l_jmeaning);
8458 psa_utils.debug_other_string(g_state_level,l_full_path, 'Funds C/R: Return Code J Meaning l_jmeaning -> '||l_jmeaning);
8459 -- =========================== FND LOG =============================
8460
8461 -- =========================== XML OUT =============================
8462 fnd_file.put_line(fnd_file.output, ' <G_JE_BATCH_NAME>');
8463 fnd_file.put_line(fnd_file.output, ' <JE_BATCH_NAME>'||l_bc_pkts(x).je_batch_name||'</JE_BATCH_NAME>');
8464 fnd_file.put_line(fnd_file.output, ' <PERIOD_NAME>'||l_bc_pkts(x).period_name||'</PERIOD_NAME>');
8465 fnd_file.put_line(fnd_file.output, ' <FC_RESULT>'||l_fmeaning||'</FC_RESULT>');
8466 fnd_file.put_line(fnd_file.output, ' <JE_F_STATUS>'||l_jmeaning||'</JE_F_STATUS>');
8467 fnd_file.put_line(fnd_file.output, ' </G_JE_BATCH_NAME>');
8468 -- =========================== XML OUT =============================
8469
8470 END IF;
8471
8472 END LOOP; --End of loop for all l_bc_pkts
8473
8474 -- =========================== XML OUT =============================
8475 IF (l_xml_b_header <> TRUE) THEN
8476 fnd_file.put_line(fnd_file.output, ' </LIST_G_JE_BATCH_NAME>');
8477 END IF;
8478 -- =========================== XML OUT =============================
8479
8480 -- =========================== FND LOG ===========================
8481 fnd_file.put_line(fnd_file.log, 'Funds C/R: -------------------------------');
8482 -- =========================== FND LOG ===========================
8483
8484 --Now processing failed batches/packets.
8485 FOR x in 1..l_failed_bc_pkts.count
8486 LOOP
8487 fnd_file.put_line(fnd_file.log, 'Funds C/R: Failed Funds Check Packets Info');
8488 fnd_file.put_line(fnd_file.log, 'Funds C/R: -------------------------------');
8489 fnd_file.put_line(fnd_file.log, 'Funds C/R: Packet Id: '||
8490 l_failed_bc_pkts(x).packet_id||
8491 ' Batch Id: '||
8492 l_failed_bc_pkts(x).je_batch_id||
8493 ' Batch Name: '||l_failed_bc_pkts(x).je_batch_name);
8494
8495
8496 -- =========================== XML OUT =============================
8497 IF (l_xml_f_b_header <> FALSE) THEN
8498 fnd_file.put_line(fnd_file.output, ' <FAILED_BATCHES_EXIST>YES</FAILED_BATCHES_EXIST>');
8499 fnd_file.put_line(fnd_file.output, ' <LIST_G_FAILURE_JE_BATCH_NAME>');
8500 l_xml_f_b_header := FALSE;
8501 END IF;
8502 -- =========================== XML OUT =============================
8503
8504 -- =========================== XML OUT =============================
8505 fnd_file.put_line(fnd_file.output, ' <G_FAILURE_JE_BATCH_NAME>');
8506 fnd_file.put_line(fnd_file.output, ' <FA_FAILURES_WARNINGS>'||l_failure_warning||'</FA_FAILURES_WARNINGS>');
8507 fnd_file.put_line(fnd_file.output, ' <F_JE_BATCH_NAME>'||l_failed_bc_pkts(x).je_batch_name||'</F_JE_BATCH_NAME>');
8508 -- =========================== XML OUT =============================
8509
8510
8511 l_je_stmt := 'SELECT ';
8512 l_je_first := TRUE;
8513 FOR a in c_seg_info(l_ledger_id)
8514 LOOP
8515 IF (l_je_first <> FALSE) THEN
8516 l_je_stmt := l_je_stmt||'c.'||a.application_column_name;
8517 l_je_first := FALSE;
8518 ELSE
8519 l_je_stmt := l_je_stmt||'||''.''||'||'c.'||a.application_column_name;
8520 END IF;
8521
8522 END LOOP; --End of segments loop
8523
8524 l_je_stmt := l_je_stmt||', SUBSTRB(h.name,1,20), h.je_header_id, l.je_line_num, l.entered_dr, '||
8525 'l.entered_cr, lk.description, p.result_code, l.code_combination_id, '||
8526 'p.rowid '||
8527 'FROM gl_je_lines l, gl_je_headers h, gl_code_combinations c, '||
8528 'gl_lookups lk, gl_bc_packets p '||
8529 'WHERE p.je_batch_id = '||l_failed_bc_pkts(x).je_batch_id||
8530 ' and p.packet_id = '||l_failed_bc_pkts(x).packet_id||
8531 ' and p.ledger_id = '||l_ledger_id||
8532 ' and p.je_header_id = h.je_header_id'||
8533 ' and h.je_header_id = l.je_header_id'||
8534 ' and p.je_line_num = l.je_line_num'||
8535 ' and p.result_code = lk.lookup_code'||
8536 ' and lk.lookup_type = ''FUNDS_CHECK_RESULT_CODE'''||
8537 ' and p.code_combination_id = c.code_combination_id (+)'||
8538 ' and nvl(p.template_id,-1) = -1'||
8539 ' and p.ussgl_link_to_parent_id is null'||
8540 ' and (p.result_code like ''F%'' or p.result_code like ''P2%'') '||
8541 ' order by l.je_header_id, l.je_line_num';
8542
8543 fnd_file.put_line(fnd_file.log, 'Funds C/R: l_je_stmt -> '|| l_je_stmt);
8544
8545 l_xml_je_lines_header := TRUE;
8546
8547 OPEN l_je_lines FOR l_je_stmt;
8548
8549 LOOP
8550 FETCH l_je_lines INTO l_seg_ccid, l_je_header_name, l_je_header_id, l_je_line_num, l_entered_dr,
8551 l_entered_cr, l_line_description, l_line_result_code, l_ccid, l_rowid;
8552
8553 -- =========================== FND LOG ===========================
8554 fnd_file.put_line(fnd_file.log, 'Funds C/R: '|| l_seg_ccid||' '||l_je_header_name||' '||l_je_header_id
8555 ||' '||l_je_line_num||' '||l_entered_dr||' '||l_entered_cr||
8556 ' '||l_line_description||' '||l_line_result_code||' '||l_ccid||
8557 ' '||l_rowid);
8558 -- =========================== FND LOG ===========================
8559 EXIT WHEN l_je_lines%NOTFOUND;
8560
8561 BEGIN
8562 SELECT
8563 l.meaning
8564 INTO
8565 l_priority
8566 FROM
8567 gl_lookups l
8568 WHERE
8569 l.lookup_type = 'BC_SEVERITY_FLAG'
8570 AND l.lookup_code = upper(substr(l_line_result_code,1,1));
8571
8572 EXCEPTION
8573 WHEN OTHERS THEN
8574 -- =========================== FND LOG ===========================
8575 psa_utils.debug_other_string(g_excep_level,l_full_path, 'Funds C/R: Failed to fetch meaning from gl_lookups');
8576 fnd_file.put_line(fnd_file.log, 'Funds C/R: Failed to fetch meaning from gl_lookups');
8577 -- ========================= FND LOG =============================
8578 END;
8579
8580
8581 -- =========================== FND LOG ===========================
8582 fnd_file.put_line(fnd_file.log, 'Funds C/R: '||l_failed_bc_pkts(x).je_batch_name||
8583 l_je_header_name||' '||l_seg_ccid||' '||
8584 l_entered_dr||' '||l_entered_cr||
8585 ' '||l_priority);
8586 -- =========================== FND LOG ===========================
8587
8588 -- =========================== XML OUT =============================
8589 IF (l_xml_je_lines_header <> FALSE) THEN
8590 fnd_file.put_line(fnd_file.output, ' <F_JE_HEADER_NAME>'||l_je_header_name||'</F_JE_HEADER_NAME>');
8591 fnd_file.put_line(fnd_file.output, ' <LIST_G_JE_LINE>');
8592 l_xml_je_lines_header := FALSE;
8593 END IF;
8594 -- =========================== XML OUT =============================
8595
8596 -- =========================== XML OUT =============================
8597 fnd_file.put_line(fnd_file.output, ' <G_JE_LINE>');
8598 fnd_file.put_line(fnd_file.output, ' <JE_LINE>'||l_je_line_num||'</JE_LINE>');
8599 fnd_file.put_line(fnd_file.output, ' <ACCT_FLEX_FIELD>'||l_seg_ccid||'</ACCT_FLEX_FIELD>');
8600 fnd_file.put_line(fnd_file.output, ' <JE_DR>'||l_entered_dr||'</JE_DR>');
8601 fnd_file.put_line(fnd_file.output, ' <JE_CR>'||l_entered_cr||'</JE_CR>');
8602 fnd_file.put_line(fnd_file.output, ' <F_W>'||l_priority||'</F_W>');
8603 fnd_file.put_line(fnd_file.output, ' <G_DESC>');
8604 fnd_file.put_line(fnd_file.output, ' <DESC>'||l_line_description||'</DESC>');
8605 -- =========================== XML OUT =============================
8606
8607
8608 l_xml_f_sum_header := true;
8609
8610 --Start of Report Summary
8611 IF ( l_line_result_code = 'P22' OR
8612 l_line_result_code = 'P27' OR
8613 l_line_result_code = 'F01' OR
8614 l_line_result_code = 'F04' OR
8615 l_line_result_code = 'F11' OR
8616 l_line_result_code = 'F14') THEN
8617
8618 l_je_seg_stmt := 'SELECT distinct ';
8619 l_je_first := TRUE;
8620 FOR a in c_seg_info(l_ledger_id)
8621 LOOP
8622 IF (l_je_first <> FALSE) THEN
8623 l_je_seg_stmt := l_je_seg_stmt||'c.'||a.application_column_name;
8624 l_je_first := FALSE;
8625 ELSE
8626 l_je_seg_stmt := l_je_seg_stmt||'||''.''||'||'c.'||a.application_column_name;
8627 END IF;
8628
8629 END LOOP; --End of segments loop
8630
8631 l_je_seg_stmt := l_je_seg_stmt||' FROM gl_code_combinations c, gl_account_hierarchies h, '||
8632 ' gl_bc_packets p where h.detail_code_combination_id = '||
8633 l_ccid||' and p.code_combination_id = h.summary_code_combination_id '||
8634 ' and p.packet_id = '||l_failed_bc_pkts(x).packet_id||
8635 ' and c.code_combination_id = p.code_combination_id';
8636
8637 fnd_file.put_line(fnd_file.log, 'Funds C/R: l_je_seg_stmt -> '||l_je_seg_stmt);
8638
8639 OPEN l_je_sum_lines for l_je_seg_stmt;
8640 LOOP
8641 FETCH l_je_sum_lines into l_je_sum_flex;
8642 EXIT WHEN l_je_sum_lines%NOTFOUND;
8643
8644 -- =========================== XML OUT =============================
8645 IF (l_xml_f_sum_header <> FALSE) THEN
8646 fnd_file.put_line(fnd_file.output, ' <LIST_DESC_SUM>');
8647 fnd_file.put_line(fnd_file.output, ' <DESC_SUM_EXISTS>YES</DESC_SUM_EXISTS>');
8648 l_xml_f_sum_header := FALSE;
8649 END IF;
8650 -- =========================== XML OUT =============================
8651
8652 fnd_file.put_line(fnd_file.log, 'Funds C/R: l_je_sum_flex -> '||l_je_sum_flex);
8653
8654 -- =========================== XML OUT =============================
8655 fnd_file.put_line(fnd_file.output, ' <DESC_SUM>');
8656 fnd_file.put_line(fnd_file.output, ' <SUM_FLEX>'||l_je_sum_flex||'</SUM_FLEX>');
8657 fnd_file.put_line(fnd_file.output, ' </DESC_SUM>');
8658 -- =========================== XML OUT =============================
8659
8660 END LOOP; --End of l_je_sum_lines cursor
8661
8662 CLOSE l_je_sum_lines;
8663 -- =========================== XML OUT =============================
8664 IF (l_xml_f_sum_header <> TRUE) THEN
8665 fnd_file.put_line(fnd_file.output, ' </LIST_DESC_SUM>');
8666 l_xml_f_sum_header := TRUE;
8667 END IF;
8668 -- =========================== XML OUT =============================
8669
8670
8671 END IF; --Summary Report End
8672
8673 --Budgetary Report Start
8674 l_xml_f_bud_header := true;
8675 l_je_bud_stmt := 'SELECT ';
8676 l_je_first := TRUE;
8677 FOR a in c_seg_info(l_ledger_id)
8678 LOOP
8679 IF (l_je_first <> FALSE) THEN
8680 l_je_bud_stmt := l_je_bud_stmt||'c.'||a.application_column_name;
8681 l_je_first := FALSE;
8682 ELSE
8683 l_je_bud_stmt := l_je_bud_stmt||'||''.''||'||'c.'||a.application_column_name;
8684 END IF;
8685
8686 END LOOP; --End of segments loop
8687
8688 BEGIN
8689 SELECT
8690 nvl(ussgl_parent_id, 0)
8691 INTO
8692 l_ussgl_parent_id
8693 FROM
8694 gl_bc_packets
8695 WHERE
8696 rowid = l_rowid;
8697 EXCEPTION
8698 WHEN OTHERS THEN
8699 -- =========================== FND LOG ===========================
8700 psa_utils.debug_other_string(g_excep_level,l_full_path, 'Funds C/R: Failed to fetch ussgl_parent_id from gl_bc_packets');
8701 fnd_file.put_line(fnd_file.log, 'Funds C/R: Failed to fetch ussgl_parent_id from gl_bc_packets');
8702 -- ========================= FND LOG =============================
8703 END;
8704
8705 l_je_bud_stmt := l_je_bud_stmt||' , p.entered_dr, p.entered_cr, p.result_code, l.description, '||
8706 ' c.code_combination_id FROM gl_code_combinations c, gl_bc_packets p, '||
8707 ' gl_lookups l WHERE p.ussgl_link_to_parent_id = '||l_ussgl_parent_id||
8708 ' and p.packet_id = '||l_failed_bc_pkts(x).packet_id||
8709 ' and c.code_combination_id = p.code_combination_id'||
8710 ' and p.result_code between ''F00'' AND ''F30'' and '||
8711 ' p.result_code = l.lookup_code and l.lookup_type = ''FUNDS_CHECK_RESULT_CODE'' '||
8712 ' order by p.code_combination_id';
8713
8714 fnd_file.put_line(fnd_file.log, 'Funds C/R: l_je_bud_stmt -> '||l_je_bud_stmt);
8715
8716 OPEN l_je_bud_lines for l_je_bud_stmt;
8717 LOOP
8718 FETCH l_je_bud_lines into l_je_bud_flex, l_je_bud_dr, l_je_bud_cr, l_je_bud_result_code,
8719 l_je_bud_desc, l_je_bud_ccid;
8720
8721 EXIT WHEN l_je_bud_lines%NOTFOUND;
8722 fnd_file.put_line(fnd_file.log, 'Funds C/R: l_je_bud_flex -> '||l_je_bud_flex
8723 ||'l_je_bud_dr ->' ||l_je_bud_dr
8724 ||'l_je_bud_cr ->' ||l_je_bud_cr
8725 ||'l_je_bud_result_code ->' ||l_je_bud_result_code
8726 ||'l_je_bud_desc ->' ||l_je_bud_desc
8727 ||'l_je_bud_ccid ->' ||l_je_bud_ccid
8728 );
8729
8730 -- =========================== XML OUT =============================
8731 IF (l_xml_f_bud_header <> FALSE) THEN
8732 fnd_file.put_line(fnd_file.output, ' <LIST_DESC_BUD>');
8733 fnd_file.put_line(fnd_file.output, ' <DESC_BUD_EXISTS>YES</DESC_BUD_EXISTS>');
8734 l_xml_f_bud_header := FALSE;
8735 END IF;
8736 -- =========================== XML OUT =============================
8737
8738 -- =========================== XML OUT =============================
8739 fnd_file.put_line(fnd_file.output, ' <G_DESC_BUD>');
8740 fnd_file.put_line(fnd_file.output, ' <DESC_BUD_FLEX>'||l_je_bud_flex||'</DESC_BUD_FLEX>');
8741 fnd_file.put_line(fnd_file.output, ' <DESC_BUD_DR>'||l_je_bud_dr||'</DESC_BUD_DR>');
8742 fnd_file.put_line(fnd_file.output, ' <DESC_BUD_CR>'||l_je_bud_cr||'</DESC_BUD_CR>');
8743 fnd_file.put_line(fnd_file.output, ' <DESC_BUD_DESC>'||l_je_bud_desc||'</DESC_BUD_DESC>');
8744 fnd_file.put_line(fnd_file.output, ' </G_DESC_BUD>');
8745 -- =========================== XML OUT =============================
8746
8747 l_xml_f_bud_sum_header := true;
8748
8749 IF ( l_je_bud_result_code = 'F11' OR
8750 l_je_bud_result_code = 'F14' OR
8751 l_je_bud_result_code = 'F01' OR
8752 l_je_bud_result_code = 'F04')THEN
8753
8754 --Summary Report with the l_je_bud_ccid
8755 l_je_bud_seg_stmt := 'SELECT distinct ';
8756 l_je_first := TRUE;
8757 FOR a in c_seg_info(l_ledger_id)
8758 LOOP
8759 IF (l_je_first <> FALSE) THEN
8760 l_je_bud_seg_stmt := l_je_bud_seg_stmt||'c.'||a.application_column_name;
8761 l_je_first := FALSE;
8762 ELSE
8763 l_je_bud_seg_stmt := l_je_bud_seg_stmt||'||''.''||'||'c.'||a.application_column_name;
8764 END IF;
8765
8766 END LOOP; --End of segments loop
8767
8768 l_je_bud_seg_stmt := l_je_bud_seg_stmt||' FROM gl_code_combinations c, gl_account_hierarchies h, '||
8769 ' gl_bc_packets p where h.detail_code_combination_id = '||
8770 l_je_bud_ccid||' and p.code_combination_id = h.summary_code_combination_id '||
8771 ' and p.packet_id = '||l_failed_bc_pkts(x).packet_id||
8772 ' and c.code_combination_id = p.code_combination_id';
8773
8774 fnd_file.put_line(fnd_file.log, 'Funds C/R: l_je_bud_seg_stmt -> '||l_je_bud_seg_stmt);
8775
8776 OPEN l_je_sum_lines for l_je_bud_seg_stmt;
8777 LOOP
8778 FETCH l_je_sum_lines into l_je_bud_sum_flex;
8779 EXIT WHEN l_je_sum_lines%NOTFOUND;
8780 fnd_file.put_line(fnd_file.log, 'Funds C/R: l_je_bud_sum_flex -> '||l_je_bud_sum_flex);
8781
8782 -- =========================== XML OUT =============================
8783 IF (l_xml_f_bud_sum_header <> FALSE) THEN
8784 fnd_file.put_line(fnd_file.output, ' <LIST_DESC_BUD_SUM>');
8785 fnd_file.put_line(fnd_file.output, ' <DESC_BUD_SUM_EXISTS>YES</DESC_BUD_SUM_EXISTS>');
8786 l_xml_f_bud_sum_header := FALSE;
8787 END IF;
8788 -- =========================== XML OUT =============================
8789 -- =========================== XML OUT =============================
8790 fnd_file.put_line(fnd_file.output, ' <DESC_BUD_SUM>');
8791 fnd_file.put_line(fnd_file.output, ' <BUD_SUM_FLEX>'||l_je_bud_sum_flex||'</BUD_SUM_FLEX>');
8792 fnd_file.put_line(fnd_file.output, ' </DESC_BUD_SUM>');
8793 -- =========================== XML OUT =============================
8794
8795
8796
8797 END LOOP; --End of l_je_sum_lines cursor
8798 CLOSE l_je_sum_lines;
8799 -- =========================== XML OUT =============================
8800 IF (l_xml_f_bud_sum_header <> TRUE) THEN
8801 fnd_file.put_line(fnd_file.output, ' </LIST_DESC_BUD_SUM>');
8802 l_xml_f_bud_sum_header := TRUE;
8803 END IF;
8804 -- =========================== XML OUT =============================
8805
8806
8807 END IF; --End Report Summary
8808
8809 END LOOP; --End of l_je_bud_lines cursor
8810
8811 -- =========================== XML OUT =============================
8812 IF (l_xml_f_bud_header <> TRUE) THEN
8813 fnd_file.put_line(fnd_file.output, ' </LIST_DESC_BUD>');
8814 l_xml_f_bud_header := TRUE;
8815 END IF;
8816 -- =========================== XML OUT =============================
8817
8818 CLOSE l_je_bud_lines;
8819
8820 -- =========================== XML OUT =============================
8821 fnd_file.put_line(fnd_file.output, ' </G_DESC>');
8822 fnd_file.put_line(fnd_file.output, ' </G_JE_LINE>');
8823 -- =========================== XML OUT =============================
8824
8825
8826 END LOOP;
8827
8828 CLOSE l_je_lines;
8829 -- =========================== XML OUT =============================
8830 IF (l_xml_je_lines_header <> TRUE) THEN
8831 fnd_file.put_line(fnd_file.output, ' </LIST_G_JE_LINE>');
8832 END IF;
8833 fnd_file.put_line(fnd_file.output, ' </G_FAILURE_JE_BATCH_NAME>');
8834 -- =========================== XML OUT =============================
8835
8836 END LOOP; -- End of failed pkts loop
8837 -- =========================== XML OUT =============================
8838 IF (l_xml_f_b_header <> TRUE) THEN
8839 fnd_file.put_line(fnd_file.output, ' </LIST_G_FAILURE_JE_BATCH_NAME>');
8840 END IF;
8841 -- =========================== XML OUT =============================
8842
8843 <<NORMAL_EXIT>>
8844 -- =========================== XML OUT =============================
8845 fnd_file.put_line(fnd_file.output, '</REPORT_ROOT>');
8846 -- =========================== XML OUT =============================
8847
8848
8849 IF sel1%ISOPEN THEN
8850 CLOSE sel1;
8851
8852 ELSIF sel2%ISOPEN THEN
8853 CLOSE sel2;
8854
8855 END IF;
8856
8857 COMMIT;
8858
8859 END;
8860
8861
8862 /*=======================================================================+
8863 | Function : GET_DEBUG |
8864 | Description : Returns value stored in g_debug variable. |
8865 | This was used by some sub-ledger team in 11i. Not sure |
8866 | if its still applicable for R12. Will check and remove. |
8867 +=======================================================================*/
8868 FUNCTION get_debug RETURN VARCHAR2 IS
8869 BEGIN
8870 return g_debug;
8871 END get_debug;
8872
8873
8874 /*=======================================================================+
8875 | Function : GLSIBC |
8876 | Description : Procedure added by Abhishek |
8877 +=======================================================================*/
8878
8879 PROCEDURE glsibc (p_last_updated_by NUMBER,
8880 p_new_template_id NUMBER,
8881 p_ledger_id NUMBER) IS
8882
8883 l_full_path VARCHAR2(100);
8884 BEGIN
8885 l_full_path := g_path||'Glsibc';
8886
8887 INSERT INTO GL_BC_PACKETS
8888 (packet_id,
8889 ledger_id,
8890 je_source_name,
8891 je_category_name,
8892 code_combination_id,
8893 actual_flag,
8894 period_name,
8895 period_year,
8896 period_num,
8897 quarter_num,
8898 currency_code,
8899 status_code,
8900 last_update_date,
8901 last_updated_by,
8902 budget_version_id,
8903 encumbrance_type_id,
8904 template_id,
8905 entered_dr,
8906 entered_cr,
8907 accounted_dr,
8908 accounted_cr,
8909 funding_budget_version_id,
8910 funds_check_level_code,
8911 amount_type,
8912 boundary_code,
8913 dr_cr_code,
8914 account_category_code,
8915 effect_on_funds_code,
8916 result_code,
8917 session_id,
8918 serial_id,
8919 application_id)
8920 SELECT
8921 min(BP.packet_id),
8922 min(BP.ledger_id),
8923 min(BP.je_source_name),
8924 min(BP.je_category_name),
8925 min(AH.summary_code_combination_id),
8926 min(BP.actual_flag),
8927 min(BP.period_name),
8928 min(BP.period_year),
8929 min(BP.period_num),
8930 min(BP.quarter_num),
8931 min(BP.currency_code),
8932 'A', /* approved */
8933 SYSDATE,
8934 p_last_updated_by,
8935 min(decode(BP.actual_flag, 'B', BP.budget_version_id, NULL)),
8936 min(decode(BP.actual_flag, 'E', BP.encumbrance_type_id, NULL)),
8937 p_new_template_id,
8938 sum(nvl(BP.entered_dr,0)),
8939 sum(nvl(BP.entered_cr,0)),
8940 sum(nvl(BP.accounted_dr,0)),
8941 sum(nvl(BP.accounted_cr,0)),
8942 SB.funding_budget_version_id,
8943 SB.funds_check_level_code,
8944 SB.amount_type,
8945 SB.boundary_code,
8946 SB.dr_cr_code,
8947 min(ST.account_category_code),
8948 decode(
8949 decode(min(BP.actual_flag) || SB.dr_cr_code ||
8950 min(ST.account_category_code),
8951 'BCP', 'dec',
8952 'ADP', 'dec',
8953 'EDP', 'dec',
8954 'ACB', 'dec',
8955 'inc'),
8956 'dec', /* +ve net dr => decreasing fa */
8957 decode(sign(sum(nvl(BP.accounted_dr,0) - nvl(BP.accounted_cr,0))),
8958 1, 'D', 'I'),
8959 'inc', /* +ve net dr => increasing fa */
8960 decode(sign(sum(nvl(BP.accounted_dr,0) - nvl(BP.accounted_cr,0))),
8961 -1, 'D', 'I')),
8962 'P04', /* P04 - This summary transaction generated does not */
8963 /* require funds check */
8964 min(BP.session_id),
8965 min(BP.serial_id),
8966 min(BP.application_id)
8967 FROM
8968 GL_ACCOUNT_HIERARCHIES AH,
8969 GL_BC_PACKETS BP,
8970 GL_BC_PACKET_ARRIVAL_ORDER AO,
8971 GL_SUMMARY_TEMPLATES ST,
8972 GL_SUMMARY_BC_OPTIONS SB,
8973 GL_BUDGETS B,
8974 GL_BUDGET_VERSIONS BV,
8975 GL_PERIOD_STATUSES PS
8976
8977 WHERE
8978 AH.ledger_id = p_ledger_id
8979 AND AH.detail_code_combination_id = BP.code_combination_id
8980 AND AH.template_id = p_new_template_id
8981 AND BP.status_code = 'A'
8982 AND BP.ledger_id = p_ledger_id
8983 AND BP.template_id IS NULL
8984 AND BP.packet_id = AO.packet_id
8985 AND BP.account_category_code = ST.account_category_code
8986 AND nvl(BP.budget_version_id, -1) = decode(BP.actual_flag, 'B',
8987 SB.funding_budget_version_id, -1)
8988 AND AO.ledger_id = p_ledger_id
8989 AND AO.affect_funds_flag = 'Y'
8990 AND ST.template_id = p_new_template_id
8991 AND SB.template_id = ST.template_id
8992 AND SB.funding_budget_version_id = BV.budget_version_id
8993 AND BV.budget_name = B.budget_name
8994 AND PS.application_id = 101
8995 AND PS.ledger_id = p_ledger_id
8996 AND PS.period_name = BP.period_name
8997 AND PS.effective_period_num >= (SELECT P1.effective_period_num
8998 FROM GL_PERIOD_STATUSES P1
8999 WHERE P1.period_name = B.first_valid_period_name
9000 AND P1.application_id = 101
9001 AND P1.ledger_id = p_ledger_id)
9002 AND PS.effective_period_num <= (SELECT P2.effective_period_num
9003 FROM GL_PERIOD_STATUSES P2
9004 WHERE P2.period_name = B.last_valid_period_name
9005 AND P2.application_id = 101
9006 AND P2.ledger_id = p_ledger_id)
9007 GROUP BY
9008 BP.packet_id,
9009 AH.summary_code_combination_id,
9010 BP.actual_flag,
9011 BP.period_name,
9012 BP.currency_code,
9013 BP.je_source_name,
9014 BP.je_category_name,
9015 BP.budget_version_id,
9016 BP.encumbrance_type_id,
9017 SB.funding_budget_version_id,
9018 SB.funds_check_level_code,
9019 SB.amount_type,
9020 SB.boundary_code,
9021 SB.dr_cr_code
9022 HAVING
9023 sum(nvl(BP.accounted_dr,0)-nvl(BP.accounted_cr,0)) <> 0;
9024
9025 -- =========================== FND LOG ===========================
9026 psa_utils.debug_other_string(g_state_level,l_full_path, ' Insert GL_BC_PACKETS -> ' || SQL%ROWCOUNT);
9027 -- ========================= FND LOG =============================
9028
9029 END glsibc;
9030
9031 /*=======================================================================+
9032 | Function : GLSFBC |
9033 | Description : Procedure added by Abhishek |
9034 +=======================================================================*/
9035
9036 PROCEDURE glsfbc (p_curr_temp_id IN NUMBER,
9037 p_ledger_id IN NUMBER,
9038 p_last_updated_by IN NUMBER) IS
9039
9040 l_full_path VARCHAR2(100);
9041 BEGIN
9042 l_full_path := g_path||'Glsfbc';
9043
9044 -- =========================== FND LOG ===========================
9045 fnd_file.put_line(fnd_file.log, 'p_curr_temp_id = '||p_curr_temp_id);
9046 fnd_file.put_line(fnd_file.log, 'p_ledger_id = '||p_ledger_id);
9047 fnd_file.put_line(fnd_file.log, 'SHRD0114 ' || '1 ' || 'stmt ' || 'Inserting into GL_BC_PACKETS ...');
9048 -- =========================== FND LOG =============================
9049
9050 INSERT INTO GL_BC_PACKETS
9051 (packet_id,
9052 ledger_id,
9053 je_source_name,
9054 je_category_name,
9055 code_combination_id,
9056 actual_flag,
9057 period_name,
9058 period_year,
9059 period_num,
9060 quarter_num,
9061 currency_code,
9062 status_code,
9063 last_update_date,
9064 last_updated_by,
9065 budget_version_id,
9066 encumbrance_type_id,
9067 template_id,
9068 entered_dr,
9069 entered_cr,
9070 accounted_dr,
9071 accounted_cr,
9072 funding_budget_version_id,
9073 funds_check_level_code,
9074 amount_type,
9075 boundary_code,
9076 dr_cr_code,
9077 account_category_code,
9078 effect_on_funds_code,
9079 result_code,
9080 session_id,
9081 serial_id,
9082 application_id)
9083 SELECT
9084 BP.packet_id,
9085 min(BP.ledger_id),
9086 BP.je_source_name,
9087 BP.je_category_name,
9088 AH.summary_code_combination_id,
9089 BP.actual_flag,
9090 BP.period_name,
9091 min(BP.period_year),
9092 min(BP.period_num),
9093 min(BP.quarter_num),
9094 BP.currency_code,
9095 'A', /* approved */
9096 SYSDATE,
9097 p_last_updated_by,
9098 min(decode(BP.actual_flag, 'B',
9099 BP.budget_version_id, NULL)),
9100 min(decode(BP.actual_flag, 'E',
9101 BP.encumbrance_type_id, NULL)),
9102 p_curr_temp_id,
9103 0, 0, 0, 0,
9104 SB.funding_budget_version_id,
9105 SB.funds_check_level_code,
9106 SB.amount_type,
9107 SB.boundary_code,
9108 SB.dr_cr_code,
9109 min(ST.account_category_code),
9110 'I',
9111 'P04', /* P04 - This summary transaction generated */
9112 /* does not require funds check */
9113 min(BP.session_id),
9114 min(BP.serial_id),
9115 min(BP.application_id)
9116 FROM
9117 GL_ACCOUNT_HIERARCHIES AH,
9118 GL_BC_PACKETS BP,
9119 GL_BC_PACKET_ARRIVAL_ORDER AO,
9120 GL_SUMMARY_TEMPLATES ST,
9121 GL_SUMMARY_BC_OPTIONS SB,
9122 GL_BUDGETS B,
9123 GL_BUDGET_VERSIONS BV,
9124 GL_PERIOD_STATUSES PS
9125 WHERE AH.ledger_id = p_ledger_id
9126 AND AH.detail_code_combination_id = BP.code_combination_id
9127 AND AH.template_id = p_curr_temp_id
9128 AND BP.status_code = 'A'
9129 AND BP.ledger_id = p_ledger_id
9130 AND BP.template_id IS NULL
9131 AND BP.packet_id = AO.packet_id
9132 AND BP.account_category_code = ST.account_category_code
9133 AND nvl(BP.budget_version_id, -1) =
9134 decode(BP.actual_flag, 'B',
9135 SB.funding_budget_version_id, -1)
9136 AND AO.ledger_id = p_ledger_id
9137 AND AO.affect_funds_flag = 'Y'
9138 AND ST.template_id = p_curr_temp_id
9139 AND NOT EXISTS
9140 ( Select 'Y'
9141 From GL_BC_PACKETS BP2
9142 Where BP2.ledger_id = p_ledger_id
9143 And BP2.template_id = p_curr_temp_id
9144 And BP2.code_combination_id = AH.summary_code_combination_id
9145 And BP2.packet_id = BP.packet_id
9146 And BP2.actual_flag = BP.actual_flag
9147 And BP2.period_name = BP.period_name
9148 And BP2.currency_code = BP.currency_code
9149 And BP2.je_source_name = BP.je_source_name
9150 And BP2.je_category_name = BP.je_category_name
9151 And nvl(BP2.encumbrance_type_id,-1) = nvl(BP.encumbrance_type_id,-1)
9152 And nvl(BP2.budget_version_id,-1) = nvl(BP.budget_version_id,-1))
9153 AND SB.template_id = p_curr_temp_id
9154 AND SB.funding_budget_version_id = BV.budget_version_id
9155 AND BV.budget_name = B.budget_name
9156 AND PS.application_id = 101
9157 AND PS.ledger_id = p_ledger_id
9158 AND PS.period_name = BP.period_name
9159 AND PS.effective_period_num >=
9160 ( Select P1.effective_period_num
9161 From GL_PERIOD_STATUSES P1
9162 Where P1.period_name = B.first_valid_period_name
9163 And P1.application_id = 101
9164 And P1.ledger_id = p_ledger_id)
9165 AND PS.effective_period_num <=
9166 ( Select P2.effective_period_num
9167 From GL_PERIOD_STATUSES P2
9168 Where P2.period_name = B.last_valid_period_name
9169 And P2.application_id = 101
9170 And P2.ledger_id = p_ledger_id)
9171 GROUP BY
9172 BP.packet_id,
9173 AH.summary_code_combination_id,
9174 BP.actual_flag,
9175 BP.period_name,
9176 BP.currency_code,
9177 BP.je_source_name,
9178 BP.je_category_name,
9179 BP.budget_version_id,
9180 BP.encumbrance_type_id,
9181 SB.funding_budget_version_id,
9182 SB.funds_check_level_code,
9183 SB.amount_type,
9184 SB.boundary_code,
9185 SB.dr_cr_code
9186
9187 HAVING
9188 sum(nvl(BP.accounted_dr,0)-nvl(BP.accounted_cr,0)) <> 0;
9189
9190 -- =========================== FND LOG ===========================
9191 psa_utils.debug_other_string(g_state_level,l_full_path, ' Insert GL_BC_PACKETS -> ' || SQL%ROWCOUNT);
9192 -- ========================= FND LOG =============================
9193
9194
9195 -- =========================== FND LOG ===========================
9196 fnd_file.put_line(fnd_file.log, 'GL_BC_PACKETS');
9197 fnd_file.put_line(fnd_file.log, 'SHRD0114 ' || '1 ' || 'stmt ' || 'Updating GL_BC_PACKETS ...');
9198 -- =========================== FND LOG =============================
9199
9200 UPDATE gl_bc_packets bp2
9201 SET (entered_dr, entered_cr, accounted_dr, accounted_cr,
9202 effect_on_funds_code) =
9203 (SELECT SUM (NVL (bp.entered_dr, 0)), SUM (NVL (bp.entered_cr,0)),
9204 SUM (NVL (bp.accounted_dr, 0)),
9205 SUM (NVL (bp.accounted_cr, 0)),
9206 DECODE (DECODE ( MIN (bp.actual_flag)
9207 || MIN(sb.dr_cr_code)
9208 || MIN (st.account_category_code),
9209 'BCP', 'dec',
9210 'ADP', 'dec',
9211 'EDP', 'dec',
9212 'ACB', 'dec',
9213 'inc'
9214 ),
9215 'dec', /* +ve net dr => decreasing fa */
9216 DECODE (SIGN (SUM ( NVL (bp.accounted_dr, 0)
9217 - NVL (bp.accounted_cr, 0)
9218 )
9219 ),
9220 1, 'D',
9221 'I'
9222 ),
9223 'inc', /* +ve net dr => increasing fa */
9224 DECODE (SIGN (SUM ( NVL (bp.accounted_dr, 0)
9225 - NVL (bp.accounted_cr, 0)
9226 )
9227 ),
9228 -1, 'D',
9229 'I'
9230 )
9231 )
9232 FROM gl_bc_packets bp,
9233 gl_account_hierarchies ah,
9234 gl_bc_packet_arrival_order ao,
9235 gl_summary_templates st,
9236 gl_summary_bc_options sb,
9237 gl_budgets b,
9238 gl_budget_versions bv,
9239 gl_period_statuses ps
9240 WHERE ah.ledger_id = p_ledger_id
9241 AND ah.template_id = p_curr_temp_id
9242 AND ah.summary_code_combination_id = bp2.code_combination_id
9243 AND st.template_id = p_curr_temp_id
9244 AND bp.status_code = 'A'
9245 AND bp.ledger_id = p_ledger_id
9246 AND bp.template_id IS NULL
9247 AND bp.code_combination_id = ah.detail_code_combination_id
9248 AND bp.account_category_code = st.account_category_code
9249 AND bp.packet_id = bp2.packet_id
9250 AND bp.actual_flag = bp2.actual_flag
9251 AND bp.period_name = bp2.period_name
9252 AND bp.currency_code = bp2.currency_code
9253 AND bp.je_source_name = bp2.je_source_name
9254 AND bp.je_category_name = bp2.je_category_name
9255 AND nvl(BP.encumbrance_type_id, -1) = nvl(BP2.encumbrance_type_id, -1)
9256 AND nvl(BP.budget_version_id,-1) = nvl(BP2.budget_version_id,-1)
9257 AND sb.template_id = p_curr_temp_id
9258 AND sb.funding_budget_version_id = bv.budget_version_id
9259 AND bv.budget_name = b.budget_name
9260 AND ps.application_id = 101
9261 AND ps.ledger_id = p_ledger_id
9262 AND ps.period_name = bp.period_name
9263 AND ps.effective_period_num >=
9264 (SELECT p1.effective_period_num
9265 FROM gl_period_statuses p1
9266 WHERE p1.period_name = b.first_valid_period_name
9267 AND p1.application_id = 101
9268 AND p1.ledger_id = p_ledger_id)
9269 AND ps.effective_period_num <=
9270 (SELECT p2.effective_period_num
9271 FROM gl_period_statuses p2
9272 WHERE p2.period_name = b.last_valid_period_name
9273 AND p2.application_id = 101
9274 AND p2.ledger_id = p_ledger_id)
9275 AND NVL (bp.budget_version_id, -1) =
9276 DECODE (bp.actual_flag,
9277 'B', sb.funding_budget_version_id,
9278 -1
9279 )
9280 AND ao.ledger_id = p_ledger_id
9281 AND ao.affect_funds_flag = 'Y'
9282 AND ao.packet_id = bp2.packet_id)
9283 WHERE bp2.ledger_id = p_ledger_id
9284 AND bp2.template_id = p_curr_temp_id
9285 AND bp2.code_combination_id IN (SELECT code_combination_id
9286 FROM gl_code_combinations
9287 WHERE template_id = p_curr_temp_id);
9288
9289 -- =========================== FND LOG ===========================
9290 psa_utils.debug_other_string(g_state_level,l_full_path, ' Update GL_BC_PACKETS -> ' || SQL%ROWCOUNT);
9291 -- ========================= FND LOG =============================
9292
9293
9294
9295 /*---------------------------------------------------+
9296 | The Delete statement will be executed here ALWAYS |
9297 +---------------------------------------------------*/
9298
9299 -- =========================== FND LOG ===========================
9300 fnd_file.put_line(fnd_file.log, 'SHRD0114 ' || '1 ' || 'stmt ' || 'Deleting from GL_BC_PACKETS ...');
9301 -- =========================== FND LOG =============================
9302
9303
9304 DELETE FROM gl_bc_packets bp
9305 WHERE bp.ledger_id = p_ledger_id
9306 AND bp.template_id = p_curr_temp_id
9307 AND bp.packet_id IN (
9308 SELECT ao.packet_id
9309 FROM gl_bc_packet_arrival_order ao
9310 WHERE ao.ledger_id = p_ledger_id
9311 AND ao.affect_funds_flag = 'Y')
9312 AND NOT EXISTS (
9313 SELECT 'Y'
9314 FROM gl_account_hierarchies ah
9315 WHERE ah.ledger_id = p_ledger_id
9316 AND ah.template_id = p_curr_temp_id
9317 AND ah.summary_code_combination_id = bp.code_combination_id);
9318
9319 -- =========================== FND LOG ===========================
9320 psa_utils.debug_other_string(g_state_level,l_full_path, ' Delete GL_BC_PACKETS -> ' || SQL%ROWCOUNT);
9321 -- ========================= FND LOG =============================
9322
9323 -- =========================== FND LOG ===========================
9324 fnd_file.put_line(fnd_file.log, 'GL_BC_PACKETS');
9325 -- =========================== FND LOG =============================
9326
9327 END glsfbc;
9328
9329 /*=======================================================================+
9330 | Function : GET_SESSION_DETAILS |
9331 | Description : Returns the session_id and serial_id of current session |
9332 +=======================================================================*/
9333
9334 PROCEDURE get_session_details(x_session_id OUT NOCOPY NUMBER,
9335 x_serial_id OUT NOCOPY NUMBER) IS
9336
9337 l_full_path VARCHAR2(100);
9338 BEGIN
9339
9340 l_full_path := g_path||'get_session_details';
9341
9342 select s.audsid, s.serial# into x_session_id, x_serial_id
9343 from v$session s, v$process p
9344 where s.paddr = p.addr
9345 and s.audsid = USERENV('SESSIONID');
9346
9347 -- =========================== FND LOG ===========================
9348 psa_utils.debug_other_string(g_state_level,l_full_path, ' x_session_id -> ' || x_session_id);
9349 psa_utils.debug_other_string(g_state_level,l_full_path, ' x_serial_id -> ' || x_serial_id);
9350 -- ========================= FND LOG =============================
9351
9352 EXCEPTION
9353 WHEN others THEN
9354 -- ========================= FND LOG ===========================
9355 psa_utils.debug_other_string(g_excep_level,l_full_path, ' EXCEPTION WHEN OTHERS ' || SQLERRM);
9356 psa_utils.debug_other_string(g_excep_level,l_full_path, ' raise');
9357 -- ========================= FND LOG ===========================
9358
9359 raise;
9360 END get_session_details;
9361
9362
9363 /*=======================================================================+
9364 | Function : POPULATE_GROUP_ID |
9365 | Description : Invoked by SLA during transfer to GL |
9366 +=======================================================================*/
9367
9368 PROCEDURE populate_group_id (p_grp_id IN NUMBER,
9369 p_application_id IN NUMBER,
9370 p_je_batch_name IN VARCHAR2 DEFAULT NULL) IS
9371 l_full_path VARCHAR2(100);
9372 BEGIN
9373 l_full_path := g_path||'Populate_Group_Id';
9374
9375 UPDATE gl_bc_packets
9376 SET group_id = p_grp_id,
9377 je_batch_name = p_je_batch_name
9378 WHERE ae_header_id IN (SELECT ae_header_id
9379 FROM xla_ae_headers
9380 WHERE group_id = p_grp_id
9381 and application_id = p_application_id);
9382
9383 -- =========================== FND LOG ===========================
9384 psa_utils.debug_other_string(g_state_level,l_full_path, ' Update GL_BC_PACKETS -> ' || SQL%ROWCOUNT);
9385 -- ========================= FND LOG =============================
9386
9387 END populate_group_id;
9388
9389
9390 /*===========================================================================================+
9391 | Function : DEBUG_XLA_INSERT |
9392 | Description : This Procedure inserts data from global temporary SLA tables |
9393 | to PSA tables as shown below: |
9394 | |
9395 | SLA Table PSA Table |
9396 | ======== ======== |
9397 | xla_events_gt psa_xla_events_logs |
9398 | xla_validation_lines_gt psa_xla_validation_lines_logs |
9399 | xla_ae_lines_gt psa_xla_ae_lines_logs |
9400 | xla_ae_headers_gt psa_xla_ae_headers_logs |
9401 | |
9402 +===========================================================================================*/
9403
9404 PROCEDURE debug_xla_insert ( xla_events IN xla_events_table ,
9405 xla_validation_lines IN xla_validation_lines_table ,
9406 xla_ae_lines IN xla_ae_lines_table ,
9407 xla_ae_headers IN xla_ae_headers_table ,
9408 xla_distribution_links IN xla_distribution_links_table) IS
9409
9410 PRAGMA autonomous_transaction;
9411 i NUMBER;
9412
9413 BEGIN
9414
9415 FORALL i IN 1 .. xla_events.count
9416 INSERT INTO psa_xla_events_logs
9417 VALUES xla_events(i);
9418
9419 FORALL i IN 1 .. xla_validation_lines.count
9420 INSERT INTO psa_xla_validation_lines_logs
9421 VALUES xla_validation_lines(i);
9422
9423 FORALL i IN 1 .. xla_ae_lines.count
9424 INSERT INTO psa_xla_ae_lines_logs
9425 VALUES xla_ae_lines(i);
9426
9427 FORALL i IN 1 .. xla_ae_headers.count
9428 INSERT INTO psa_xla_ae_headers_logs
9429 VALUES xla_ae_headers(i);
9430
9431
9432 FORALL i IN 1 .. xla_distribution_links.count
9433 INSERT INTO psa_xla_dist_links_logs
9434 VALUES xla_distribution_links(i);
9435 COMMIT;
9436
9437 END debug_xla_insert ;
9438
9439
9440 /*===========================================================================================+
9441 | Function : DEBUG_XLA |
9442 | Description : This Procedure is used for SLA debugging purpose. |
9443 | It calls DEBUG_XLA_INSERT procedure to transfer data |
9444 | from global temporary SLA tables to PSA tables. |
9445 | |
9446 +===========================================================================================*/
9447
9448 PROCEDURE debug_xla (phase IN VARCHAR2) IS
9449
9450 l_xla_events xla_events_table;
9451 l_xla_validation_lines xla_validation_lines_table;
9452 l_xla_ae_lines xla_ae_lines_table;
9453 l_xla_ae_headers xla_ae_headers_table;
9454 l_xla_distribution_links xla_distribution_links_table;
9455
9456 BEGIN
9457
9458 IF g_xla_debug THEN
9459
9460 SELECT line_number,
9461 entity_id,
9462 application_id,
9463 ledger_id,
9464 entity_code,
9465 source_id_int_1,
9466 source_id_char_1,
9467 event_id,
9468 event_class_code,
9469 event_status_code,
9470 process_status_code,
9471 reference_num_1,
9472 reference_char_1,
9473 on_hold_flag,
9474 transaction_date,
9475 budgetary_control_flag,
9476 phase,
9477 sysdate
9478 BULK COLLECT INTO l_xla_events
9479 FROM xla_events_gt ;
9480
9481
9482 SELECT event_id,
9483 entity_id,
9484 ae_header_id,
9485 ae_line_num,
9486 accounting_date,
9487 balance_type_code,
9488 je_category_name,
9489 budget_version_id,
9490 ledger_id,
9491 entered_currency_code,
9492 entered_dr,
9493 entered_cr,
9494 accounted_dr,
9495 accounted_cr,
9496 code_combination_id,
9497 balancing_line_type,
9498 encumbrance_type_id,
9499 accounting_entry_status_code,
9500 period_name,
9501 phase,
9502 sysdate
9503 BULK COLLECT INTO l_xla_validation_lines
9504 FROM xla_validation_lines_gt ;
9505
9506
9507 SELECT ae_header_id,
9508 ae_line_num,
9509 source_distribution_id_char_1,
9510 source_distribution_id_char_2,
9511 source_distribution_id_char_3,
9512 source_distribution_id_char_4,
9513 source_distribution_id_char_5,
9514 source_distribution_id_num_1,
9515 source_distribution_id_num_2,
9516 source_distribution_id_num_3,
9517 source_distribution_id_num_4,
9518 source_distribution_id_num_5,
9519 source_distribution_type,
9520 bflow_application_id,
9521 bflow_entity_code,
9522 bflow_source_id_num_1,
9523 bflow_source_id_num_2,
9524 bflow_source_id_num_3,
9525 bflow_source_id_num_4,
9526 bflow_source_id_char_1,
9527 bflow_source_id_char_2,
9528 bflow_source_id_char_3,
9529 bflow_source_id_char_4,
9530 bflow_distribution_type,
9531 bflow_dist_id_num_1,
9532 bflow_dist_id_num_2,
9533 bflow_dist_id_num_3,
9534 bflow_dist_id_num_4,
9535 bflow_dist_id_num_5,
9536 bflow_dist_id_char_1,
9537 bflow_dist_id_char_2,
9538 bflow_dist_id_char_3,
9539 bflow_dist_id_char_4,
9540 bflow_dist_id_char_5,
9541 phase,
9542 sysdate
9543 BULK COLLECT INTO l_xla_ae_lines
9544 FROM xla_ae_lines_gt ;
9545
9546
9547 SELECT ae_header_id,
9548 ledger_id,
9549 event_id,
9550 event_type_code,
9551 accounting_entry_status_code ,
9552 balance_type_code,
9553 funds_status_code,
9554 phase,
9555 sysdate
9556 BULK COLLECT INTO l_xla_ae_headers
9557 FROM xla_ae_headers_gt ;
9558
9559 Select application_id ,
9560 event_id,
9561 ae_header_id,
9562 ae_line_num ,
9563 source_distribution_type ,
9564 source_distribution_id_char_1,
9565 source_distribution_id_char_2,
9566 source_distribution_id_char_3,
9567 source_distribution_id_char_4,
9568 source_distribution_id_char_5,
9569 source_distribution_id_num_1 ,
9570 source_distribution_id_num_2 ,
9571 source_distribution_id_num_3 ,
9572 source_distribution_id_num_4 ,
9573 source_distribution_id_num_5 ,
9574 tax_line_ref_id ,
9575 tax_summary_line_ref_id ,
9576 tax_rec_nrec_dist_ref_id ,
9577 statistical_amount,
9578 ref_ae_header_id ,
9579 ref_temp_line_num ,
9580 accounting_line_code,
9581 accounting_line_type_code,
9582 merge_duplicate_code ,
9583 temp_line_num ,
9584 ref_event_id ,
9585 line_definition_owner_code ,
9586 line_definition_code ,
9587 event_class_code ,
9588 event_type_code ,
9589 upg_batch_id ,
9590 calculate_acctd_amts_flag,
9591 calculate_g_l_amts_flag ,
9592 gain_or_loss_ref,
9593 rounding_class_code ,
9594 document_rounding_level,
9595 unrounded_entered_dr,
9596 unrounded_entered_cr ,
9597 doc_rounding_entered_amt,
9598 doc_rounding_acctd_amt,
9599 unrounded_accounted_cr ,
9600 unrounded_accounted_dr ,
9601 alloc_to_application_id,
9602 alloc_to_entity_code,
9603 alloc_to_source_id_num_1,
9604 alloc_to_source_id_num_2,
9605 alloc_to_source_id_num_3,
9606 alloc_to_source_id_num_4,
9607 alloc_to_source_id_char_1,
9608 alloc_to_source_id_char_2,
9609 alloc_to_source_id_char_3,
9610 alloc_to_source_id_char_4,
9611 alloc_to_distribution_type,
9612 alloc_to_dist_id_num_1,
9613 alloc_to_dist_id_num_2,
9614 alloc_to_dist_id_num_3,
9615 alloc_to_dist_id_num_4,
9616 alloc_to_dist_id_num_5,
9617 alloc_to_dist_id_char_1,
9618 alloc_to_dist_id_char_2,
9619 alloc_to_dist_id_char_3,
9620 alloc_to_dist_id_char_4,
9621 alloc_to_dist_id_char_5,
9622 applied_to_application_id,
9623 applied_to_entity_code ,
9624 applied_to_entity_id ,
9625 applied_to_source_id_num_1,
9626 applied_to_source_id_num_2,
9627 applied_to_source_id_num_3 ,
9628 applied_to_source_id_num_4 ,
9629 applied_to_source_id_char_1,
9630 applied_to_source_id_char_2,
9631 applied_to_source_id_char_3,
9632 applied_to_source_id_char_4,
9633 applied_to_distribution_type,
9634 applied_to_dist_id_num_1,
9635 applied_to_dist_id_num_2,
9636 applied_to_dist_id_num_3,
9637 applied_to_dist_id_num_4,
9638 applied_to_dist_id_num_5,
9639 applied_to_dist_id_char_1,
9640 applied_to_dist_id_char_2,
9641 applied_to_dist_id_char_3,
9642 applied_to_dist_id_char_4,
9643 applied_to_dist_id_char_5,
9644 phase,
9645 sysdate
9646 BULK COLLECT INTO l_xla_distribution_links
9647 FROM xla_distribution_links d
9648 where exists (select 1
9649 from xla_ae_headers h
9650 where h.event_id IN (SELECT event_id from psa_bc_xla_events_gt)
9651 and h.ae_header_id = d.ae_header_id)
9652 and application_id = psa_bc_xla_pvt.g_application_id;
9653
9654
9655
9656 DEBUG_XLA_INSERT ( l_xla_events, l_xla_validation_lines, l_xla_ae_lines, l_xla_ae_headers , l_xla_distribution_links);
9657
9658 ELSE
9659 return;
9660
9661 END IF;
9662
9663 END debug_xla;
9664
9665 PROCEDURE check_for_xla_errors
9666 (
9667 p_error_type IN VARCHAR2 DEFAULT NULL,
9668 p_return_code OUT NOCOPY VARCHAR2
9669 )
9670 IS
9671 l_full_path VARCHAR2(100);
9672 l_message VARCHAR2(2000);
9673 BEGIN
9674 l_full_path := g_path||'check_for_xla_errors';
9675 p_return_code := 'N';
9676 psa_utils.debug_other_string(g_state_level,l_full_path, 'Inside Program');
9677 psa_utils.debug_other_string(g_state_level,l_full_path, 'p_error_type='||p_error_type);
9678 IF (p_error_type = 'BFLOW') THEN
9679 psa_utils.debug_other_string(g_state_level,l_full_path, 'Checking for BFLOW Errors');
9680 FOR bflow_rec IN (SELECT l.*,
9681 e.entity_id event_entiity_id
9682 FROM xla_ae_lines_gt l,
9683 xla_events_gt e
9684 WHERE l.event_id = e.event_id
9685 AND business_method_code = 'PRIOR_ENTRY'
9686 AND code_combination_status_code = 'INVALID'
9687 AND NVL(bflow_prior_entry_status_code, 'N') <> 'F') LOOP
9688 l_message := 'Related BC Accounting Missing for '||
9689 ' Event id: '||bflow_rec.event_id||
9690 ' Event Type Code: '||bflow_rec.event_type_code ||
9691 ' Distribution Id: '||bflow_rec.source_distribution_id_num_1||
9692 ' Related Application Id: '||bflow_rec.bflow_application_id||
9693 ' Related Entity Code: '||bflow_rec.bflow_entity_code||
9694 ' Related Source identifier Num 1: '||bflow_rec.bflow_source_id_num_1||
9695 ' Related Distribution Type: '||bflow_rec.bflow_distribution_type||
9696 ' Related Distribution Identifier Num 1: '||bflow_rec.bflow_dist_id_num_1;
9697 Fnd_message.set_name('PSA','PSA_BC_XLA_ERROR');
9698 Fnd_Message.Set_Token('PARAM_NAME',l_message);
9699 -- Fnd_Msg_Pub.ADD;
9700 psa_bc_xla_pvt.psa_xla_error
9701 (
9702 p_message_code => 'PSA_BC_XLA_ERROR',
9703 p_event_id => bflow_rec.event_id
9704 );
9705 p_return_code := 'Y';
9706 END LOOP;
9707 ELSIF (p_error_type = 'EVENTS_NOT_PROCESSED') THEN
9708 psa_utils.debug_other_string(g_state_level,l_full_path, 'Checking for Events Not Processed');
9709 FOR events_rec IN (SELECT *
9710 FROM xla_events_gt e
9711 WHERE NOT EXISTS (SELECT 1
9712 FROM xla_ae_lines_gt l
9713 WHERE l.event_id = e.event_id)) LOOP
9714 l_message := 'Event '||events_rec.event_id||' is not processed.';
9715 Fnd_message.set_name('PSA','PSA_BC_XLA_ERROR');
9716 Fnd_Message.Set_Token('PARAM_NAME',l_message);
9717 psa_bc_xla_pvt.psa_xla_error
9718 (
9719 p_message_code => 'PSA_BC_XLA_ERROR',
9720 p_event_id => events_rec.event_id
9721 );
9722 p_return_code := 'Y';
9723 END LOOP;
9724 ELSIF (p_error_type = 'GL_BC_PACKETS_EMPTY') THEN
9725 psa_utils.debug_other_string(g_state_level,l_full_path, 'Checking for Events Not Processed');
9726 FOR events_rec IN (SELECT *
9727 FROM xla_events_gt e
9728 WHERE NOT EXISTS (SELECT 1
9729 FROM xla_psa_bc_lines_v l
9730 WHERE l.event_id = e.event_id)) LOOP
9731 l_message := 'Event '||events_rec.event_id||' is not processed.';
9732 Fnd_message.set_name('PSA','PSA_GL_BC_PACKETS_EMPTY');
9733 Fnd_Message.Set_Token('PARAM_NAME',l_message);
9734 psa_bc_xla_pvt.psa_xla_error
9735 (
9736 p_message_code => 'PSA_GL_BC_PACKETS_EMPTY',
9737 p_event_id => events_rec.event_id
9738 );
9739 p_return_code := 'Y';
9740 END LOOP;
9741 END IF;
9742 END;
9743
9744
9745
9746 /*===========================================================================================+
9747 | Function : BUDGETARY_CONTROL |
9748 | Description : BC API is invoked by SLA in package XLA_JE_VALIDATION_PKG.BUDGETARY_CONTROL |
9749 +===========================================================================================*/
9750
9751 FUNCTION budgetary_control (p_ledgerid IN NUMBER,
9752 p_return_code OUT NOCOPY VARCHAR2) return BOOLEAN IS
9753
9754 l_session_id gl_bc_packets.session_id%type;
9755 l_serial_id gl_bc_packets.serial_id%type;
9756
9757 l_packet_id gl_bc_packets.packet_id%type;
9758 l_bc_pkts bc_pkts_rec;
9759 l_packets num_rec;
9760 l_ret_code VARCHAR2(1);
9761 l_bc_ret_code VARCHAR2(1);
9762 l_s_status_cnt NUMBER(5);
9763 l_a_status_cnt NUMBER(5);
9764 l_f_status_cnt NUMBER(5);
9765 l_p_status_cnt NUMBER(5);
9766 l_t_status_cnt NUMBER(5);
9767 l_je_source_name xla_subledgers.je_source_name%type;
9768 invalid_je_source_name EXCEPTION;
9769 gl_bc_packets_empty EXCEPTION;
9770 l_xla_return_code VARCHAR2(1);
9771
9772
9773 -- ========================= FND LOG ===========================
9774 l_full_path VARCHAR2(100);
9775 -- ========================= FND LOG ===========================
9776
9777 CURSOR get_je_source_name (p_application_id IN NUMBER) IS
9778 SELECT je_source_name
9779 FROM xla_subledgers
9780 WHERE application_id = p_application_id;
9781
9782 CURSOR get_status_per_header (p_packet_id IN NUMBER) IS
9783 SELECT ae_header_id,
9784 count(*) total_cnt,
9785 sum(decode(status_code, 'S', 1, 0)) success_cnt,
9786 sum(decode(status_code, 'A', 1, 0)) approved_cnt,
9787 sum(decode(status_code, 'F', 1, 0)) failed_cnt,
9788 sum(decode(status_code, 'R', 1, 0)) rejected_cnt
9789 FROM gl_bc_packets
9790 WHERE packet_id = p_packet_id
9791 GROUP BY ae_header_id;
9792
9793 CURSOR get_ledger_category (p_ledgerid IN NUMBER) IS
9794 SELECT ledger_category_code
9795 FROM gl_ledgers
9796 WHERE ledger_id = p_ledgerid;
9797
9798 CURSOR debug_xla_ae_headers_gt IS
9799 SELECT ae_header_id, ledger_id, entity_id, event_id,
9800 event_type_code, funds_status_code, accounting_entry_status_code,
9801 balance_type_code
9802 FROM xla_ae_headers_gt;
9803
9804 CURSOR debug_xla_ae_lines_gt IS
9805 SELECT event_id, ae_header_id, ae_line_num
9806 FROM xla_ae_lines_gt;
9807
9808 CURSOR debug_xla_val_lines_gt IS
9809 SELECT event_id, ae_header_id, ae_line_num, period_name,
9810 accounting_entry_status_code, balancing_line_type
9811 FROM xla_validation_lines_gt;
9812
9813 CURSOR debug_xla_events_gt IS
9814 SELECT application_id, event_id, event_date, event_type_code,
9815 reference_num_1
9816 FROM xla_events_gt;
9817
9818 CURSOR debug_xla_psa_bc_v IS
9819 SELECT event_id, ae_header_id, ae_line_num, entity_id, ledger_id,
9820 period_name
9821 FROM xla_psa_bc_lines_v;
9822
9823 CURSOR debug_psa_bc_alloc_gt IS
9824 SELECT hierarchy_id, ae_header_id, ae_line_num, event_id,
9825 status_code
9826 FROM psa_bc_alloc_gt;
9827
9828 -- Check whether all the events from XLA_EVENTS_GT have come to
9829 -- XLA_AE_LINES_GT.
9830 /* If any event is missed we will treat it as
9831 FATAL error because there was some setup problem in SLA. */
9832 CURSOR c_cnt_events IS
9833 SELECT (SELECT COUNT (*)
9834 FROM xla_events_gt) event_count,
9835 (SELECT COUNT (DISTINCT (event_id))
9836 FROM xla_ae_lines_gt) ae_event_count
9837 FROM DUAL;
9838
9839 -- check whether allocation attributes are used or not
9840 /* This is to avoid additional processing for allocation attributes
9841 if they are NOT used. */
9842 CURSOR c_chk_alloc_used(p_ledgerid NUMBER) is
9843 SELECT
9844 'Allocation attributes are used'
9845 FROM DUAL
9846 WHERE EXISTS
9847 (
9848 SELECT
9849 'Related transaction allocation setup exists'
9850 FROM psa_bc_alloc_v a,
9851 psa_bc_alloc_v b
9852 WHERE a.ROW_ID <> b.ROW_ID
9853 AND a.ledger_id=p_ledgerid
9854 AND b.ledger_id=p_ledgerid
9855 AND NVL (b.alloc_to_entity_code, 'X') = NVL (a.entity_code, 'X')
9856 AND NVL (b.alloc_to_source_id_num_1, -99) = NVL (a.source_id_int_1, -99)
9857 AND NVL (b.alloc_to_source_id_num_2, -99) = NVL (a.source_id_int_2, -99)
9858 AND NVL (b.alloc_to_source_id_num_3, -99) = NVL (a.source_id_int_3, -99)
9859 AND NVL (b.alloc_to_source_id_num_4, -99) = NVL (a.source_id_int_4, -99)
9860 AND NVL (b.alloc_to_source_id_char_1, 'X') = NVL (a.source_id_char_1, 'X')
9861 AND NVL (b.alloc_to_source_id_char_2, 'X') = NVL (a.source_id_char_2, 'X')
9862 AND NVL (b.alloc_to_source_id_char_3, 'X') = NVL (a.source_id_char_3, 'X')
9863 AND NVL (b.alloc_to_source_id_char_4, 'X') = NVL (a.source_id_char_4, 'X')
9864 AND NVL (b.alloc_to_application_id, -99) = NVL (a.application_id, -99)
9865 AND NVL (b.alloc_to_distribution_type, 'X') = NVL (a.source_distribution_type, 'X')
9866 AND NVL (b.alloc_to_dist_id_num_1, -99) = NVL (a.source_distribution_id_num_1, -99)
9867 AND NVL (b.alloc_to_dist_id_num_2, -99) = NVL (a.source_distribution_id_num_2, -99)
9868 AND NVL (b.alloc_to_dist_id_num_3, -99) = NVL (a.source_distribution_id_num_3, -99)
9869 AND NVL (b.alloc_to_dist_id_num_4, -99) = NVL (a.source_distribution_id_num_4, -99)
9870 AND NVL (b.alloc_to_dist_id_num_5, -99) = NVL (a.source_distribution_id_num_5, -99)
9871 AND NVL (b.alloc_to_dist_id_char_1, 'X') = NVL (a.source_distribution_id_char_1, 'X')
9872 AND NVL (b.alloc_to_dist_id_char_2, 'X') = NVL (a.source_distribution_id_char_2, 'X')
9873 AND NVL (b.alloc_to_dist_id_char_3, 'X') = NVL (a.source_distribution_id_char_3, 'X')
9874 AND NVL (b.alloc_to_dist_id_char_4, 'X') = NVL (a.source_distribution_id_char_4, 'X')
9875 AND NVL (b.alloc_to_dist_id_char_5, 'X') = NVL (a.source_distribution_id_char_5, 'X')
9876 )
9877 AND EXISTS
9878 (
9879 SELECT
9880 'Parent transaction allocation setup exists'
9881 FROM psa_bc_alloc_v a,
9882 psa_bc_alloc_v b
9883 WHERE a.ROW_ID = b.ROW_ID
9884 AND a.ledger_id=p_ledgerid
9885 AND b.ledger_id=p_ledgerid
9886 AND NVL (b.alloc_to_entity_code, 'X') = NVL (a.entity_code, 'X')
9887 AND NVL (b.alloc_to_source_id_num_1, -99) = NVL (a.source_id_int_1, -99)
9888 AND NVL (b.alloc_to_source_id_num_2, -99) = NVL (a.source_id_int_2, -99)
9889 AND NVL (b.alloc_to_source_id_num_3, -99) = NVL (a.source_id_int_3, -99)
9890 AND NVL (b.alloc_to_source_id_num_4, -99) = NVL (a.source_id_int_4, -99)
9891 AND NVL (b.alloc_to_source_id_char_1, 'X') = NVL (a.source_id_char_1, 'X')
9892 AND NVL (b.alloc_to_source_id_char_2, 'X') = NVL (a.source_id_char_2, 'X')
9893 AND NVL (b.alloc_to_source_id_char_3, 'X') = NVL (a.source_id_char_3, 'X')
9894 AND NVL (b.alloc_to_source_id_char_4, 'X') = NVL (a.source_id_char_4, 'X')
9895 AND NVL (b.alloc_to_application_id, -99) = NVL (a.application_id, -99)
9896 AND NVL (b.alloc_to_distribution_type, 'X') = NVL (a.source_distribution_type, 'X')
9897 AND NVL (b.alloc_to_dist_id_num_1, -99) = NVL (a.source_distribution_id_num_1, -99)
9898 AND NVL (b.alloc_to_dist_id_num_2, -99) = NVL (a.source_distribution_id_num_2, -99)
9899 AND NVL (b.alloc_to_dist_id_num_3, -99) = NVL (a.source_distribution_id_num_3, -99)
9900 AND NVL (b.alloc_to_dist_id_num_4, -99) = NVL (a.source_distribution_id_num_4, -99)
9901 AND NVL (b.alloc_to_dist_id_num_5, -99) = NVL (a.source_distribution_id_num_5, -99)
9902 AND NVL (b.alloc_to_dist_id_char_1, 'X') = NVL (a.source_distribution_id_char_1, 'X')
9903 AND NVL (b.alloc_to_dist_id_char_2, 'X') = NVL (a.source_distribution_id_char_2, 'X')
9904 AND NVL (b.alloc_to_dist_id_char_3, 'X') = NVL (a.source_distribution_id_char_3, 'X')
9905 AND NVL (b.alloc_to_dist_id_char_4, 'X') = NVL (a.source_distribution_id_char_4, 'X')
9906 AND NVL (b.alloc_to_dist_id_char_5, 'X') = NVL (a.source_distribution_id_char_5, 'X')
9907 )
9908 ;
9909
9910 -- Find out the base transactions
9911 /* Base transaction (e.g. PO) will be identified as their base
9912 transaction attributes will be same as allocation attributes */
9913 CURSOR c_get_parent_trx IS
9914 SELECT
9915 DISTINCT
9916 ENTITY_CODE ,
9917 SOURCE_ID_INT_1 ,
9918 SOURCE_ID_INT_2 ,
9919 SOURCE_ID_INT_3 ,
9920 SOURCE_ID_INT_4 ,
9921 SOURCE_ID_CHAR_1 ,
9922 SOURCE_ID_CHAR_2 ,
9923 SOURCE_ID_CHAR_3 ,
9924 SOURCE_ID_CHAR_4 ,
9925 APPLICATION_ID,
9926 SOURCE_DISTRIBUTION_ID_NUM_1 ,
9927 SOURCE_DISTRIBUTION_ID_NUM_2 ,
9928 SOURCE_DISTRIBUTION_ID_NUM_3 ,
9929 SOURCE_DISTRIBUTION_ID_NUM_4 ,
9930 SOURCE_DISTRIBUTION_ID_NUM_5 ,
9931 SOURCE_DISTRIBUTION_TYPE,
9932 SOURCE_DISTRIBUTION_ID_CHAR_1 ,
9933 SOURCE_DISTRIBUTION_ID_CHAR_2 ,
9934 SOURCE_DISTRIBUTION_ID_CHAR_3 ,
9935 SOURCE_DISTRIBUTION_ID_CHAR_4 ,
9936 SOURCE_DISTRIBUTION_ID_CHAR_5
9937 FROM psa_bc_alloc_v a
9938 WHERE EXISTS
9939 (
9940 SELECT
9941 'Accounting line is allocated to itself'
9942 FROM psa_bc_alloc_v b
9943 WHERE b.ROW_ID = a.ROW_ID
9944 AND NVL(b.ALLOC_TO_ENTITY_CODE, 'X') = NVL(a.ENTITY_CODE, 'X')
9945 AND NVL(b.ALLOC_TO_SOURCE_ID_NUM_1, -99)= NVL(a.SOURCE_ID_INT_1, -99)
9946 AND NVL(b.ALLOC_TO_SOURCE_ID_NUM_2, -99) = NVL(a.SOURCE_ID_INT_2, -99)
9947 AND NVL(b.ALLOC_TO_SOURCE_ID_NUM_3, -99) = NVL(a.SOURCE_ID_INT_3, -99)
9948 AND NVL(b.ALLOC_TO_SOURCE_ID_NUM_4, -99) = NVL(a.SOURCE_ID_INT_4, -99)
9949 AND NVL(b.ALLOC_TO_SOURCE_ID_CHAR_1, 'X') = NVL(a.SOURCE_ID_CHAR_1, 'X')
9950 AND NVL(b.ALLOC_TO_SOURCE_ID_CHAR_2, 'X') = NVL(a.SOURCE_ID_CHAR_2, 'X')
9951 AND NVL(b.ALLOC_TO_SOURCE_ID_CHAR_3, 'X') = NVL(a.SOURCE_ID_CHAR_3, 'X')
9952 AND NVL(b.ALLOC_TO_SOURCE_ID_CHAR_4, 'X') = NVL(a.SOURCE_ID_CHAR_4, 'X')
9953 AND NVL(b.alloc_to_application_id, -99) = NVL (a.application_id, -99)
9954 AND NVL(b.alloc_to_distribution_type, 'X') = NVL(a.source_distribution_type, 'X')
9955 AND NVL(b.alloc_to_dist_id_num_1, -99) = NVL(a.source_distribution_id_num_1, -99)
9956 AND NVL(b.alloc_to_dist_id_num_2, -99) = NVL(a.source_distribution_id_num_2, -99)
9957 AND NVL(b.alloc_to_dist_id_num_3, -99) = NVL(a.source_distribution_id_num_3, -99)
9958 AND NVL(b.alloc_to_dist_id_num_4, -99) = NVL(a.source_distribution_id_num_4, -99)
9959 AND NVL(b.alloc_to_dist_id_num_5, -99) = NVL(a.source_distribution_id_num_5, -99)
9960 AND NVL(b.alloc_to_dist_id_char_1, 'X') = NVL(a.source_distribution_id_char_1, 'X')
9961 AND NVL(b.alloc_to_dist_id_char_2, 'X') = NVL(a.source_distribution_id_char_2, 'X')
9962 AND NVL(b.alloc_to_dist_id_char_3, 'X') = NVL(a.source_distribution_id_char_3, 'X')
9963 AND NVL(b.alloc_to_dist_id_char_4, 'X') = NVL(a.source_distribution_id_char_4, 'X')
9964 AND NVL(b.alloc_to_dist_id_char_5, 'X') = NVL(a.source_distribution_id_char_5, 'X')
9965 )
9966 ;
9967
9968 -- For each base transactions find out its child transactions
9969 CURSOR c_get_child_trx (P_ENTITY_CODE VARCHAR2 ,
9970 P_SOURCE_ID_INT_1 NUMBER ,
9971 P_SOURCE_ID_INT_2 NUMBER,
9972 P_SOURCE_ID_INT_3 NUMBER,
9973 P_SOURCE_ID_INT_4 NUMBER,
9974 P_SOURCE_ID_CHAR_1 VARCHAR2,
9975 P_SOURCE_ID_CHAR_2 VARCHAR2,
9976 P_SOURCE_ID_CHAR_3 VARCHAR2,
9977 P_SOURCE_ID_CHAR_4 VARCHAR2,
9978 P_APPLICATION_ID VARCHAR2,
9979 P_SOURCE_DIST_ID_NUM_1 NUMBER,
9980 P_SOURCE_DIST_ID_NUM_2 NUMBER,
9981 P_SOURCE_DIST_ID_NUM_3 NUMBER,
9982 P_SOURCE_DIST_ID_NUM_4 NUMBER,
9983 P_SOURCE_DIST_ID_NUM_5 NUMBER,
9984 P_SOURCE_DIST_TYPE VARCHAR2,
9985 P_SOURCE_DIST_ID_CHAR_1 VARCHAR2,
9986 P_SOURCE_DIST_ID_CHAR_2 VARCHAR2,
9987 P_SOURCE_DIST_ID_CHAR_3 VARCHAR2,
9988 P_SOURCE_DIST_ID_CHAR_4 VARCHAR2,
9989 P_SOURCE_DIST_ID_CHAR_5 VARCHAR2)
9990 IS
9991 SELECT
9992 ae_header_id,
9993 ae_line_num,
9994 event_id
9995 FROM psa_bc_alloc_v
9996 WHERE NVL(ALLOC_TO_ENTITY_CODE, 'X') = NVL(p_entity_code, 'X')
9997 AND NVL(ALLOC_TO_SOURCE_ID_NUM_1, -99) = NVL(p_source_id_int_1, -99)
9998 AND NVL(ALLOC_TO_SOURCE_ID_NUM_2, -99) = NVL(p_source_id_int_2, -99)
9999 AND NVL(ALLOC_TO_SOURCE_ID_NUM_3, -99) = NVL(p_source_id_int_3, -99)
10000 AND NVL(ALLOC_TO_SOURCE_ID_NUM_4, -99) = NVL(p_source_id_int_4, -99)
10001 AND NVL(ALLOC_TO_SOURCE_ID_CHAR_1, 'X') = NVL(p_source_id_char_1, 'X')
10002 AND NVL(ALLOC_TO_SOURCE_ID_CHAR_2, 'X') = NVL(p_source_id_char_2, 'X')
10003 AND NVL(ALLOC_TO_SOURCE_ID_CHAR_3, 'X') = NVL(p_source_id_char_3, 'X')
10004 AND NVL(ALLOC_TO_SOURCE_ID_CHAR_4, 'X') = NVL(p_source_id_char_4, 'X')
10005 AND NVL(ALLOC_TO_APPLICATION_ID, -99) = NVL(p_application_id, -99)
10006 AND NVL(ALLOC_TO_DIST_ID_NUM_1 , -99) = NVL(p_source_dist_id_num_1 , -99)
10007 AND NVL(ALLOC_TO_DIST_ID_NUM_2 , -99) = NVL(p_source_dist_id_num_2 , -99)
10008 AND NVL(ALLOC_TO_DIST_ID_NUM_3 , -99) = NVL(p_source_dist_id_num_3 , -99)
10009 AND NVL(ALLOC_TO_DIST_ID_NUM_4 , -99) = NVL(p_source_dist_id_num_4 , -99)
10010 AND NVL(ALLOC_TO_DIST_ID_NUM_5 , -99) = NVL(p_source_dist_id_num_5 , -99)
10011 AND NVL(ALLOC_TO_DISTRIBUTION_TYPE, 'X') = NVL(p_source_dist_type, 'X')
10012 AND NVL(ALLOC_TO_DIST_ID_CHAR_1 , 'X') = NVL(p_source_dist_id_char_1 , 'X')
10013 AND NVL(ALLOC_TO_DIST_ID_CHAR_2 , 'X') = NVL(p_source_dist_id_char_2 , 'X')
10014 AND NVL(ALLOC_TO_DIST_ID_CHAR_3 , 'X') = NVL(p_source_dist_id_char_3 , 'X')
10015 AND NVL(ALLOC_TO_DIST_ID_CHAR_4 , 'X') = NVL(p_source_dist_id_char_4 , 'X')
10016 AND NVL(ALLOC_TO_DIST_ID_CHAR_5 , 'X') = NVL(p_source_dist_id_char_5 , 'X')
10017 ;
10018
10019 -- Get the hierarchy id
10020 CURSOR c_get_hierarchy_id
10021 IS
10022 SELECT
10023 DISTINCT(hierarchy_id)
10024 FROM psa_bc_alloc_gt;
10025
10026 -- Check whether for a hierarchy events funds check/reserve is
10027 -- failed/rejected.
10028 CURSOR c_chk_funds_hier(p_hierarchy_id NUMBER,
10029 p_session_id NUMBER,
10030 p_serial_id NUMBER)
10031 IS
10032 SELECT 'Funds Failure for hierarchy'
10033 FROM DUAL
10034 WHERE EXISTS
10035 (SELECT 'X' FROM GL_BC_PACKETS
10036 WHERE (ae_header_id, ae_line_num, event_id)
10037 IN (select ae_header_id, ae_line_num, event_id
10038 from psa_bc_alloc_gt
10039 where hierarchy_id = p_hierarchy_id
10040 and status_code = 'P'
10041 )
10042 AND status_code IN ('F', 'R')
10043 AND session_id = p_session_id
10044 AND serial_id = p_serial_id) ;
10045
10046 CURSOR c_pkt_retcode (p_packet_id NUMBER)
10047 IS
10048 SELECT DECODE (COUNT (*),
10049 COUNT (DECODE (SUBSTR (bp.result_code, 1, 1), 'P', 1)), DECODE
10050 (SIGN (COUNT (DECODE (bp.result_code,
10051 'P20', 1,
10052 'P22', 1,
10053 'P25', 1,
10054 'P27', 1,
10055 'P31', 1,
10056 'P35', 1,
10057 'P36', 1,
10058 'P37', 1,
10059 'P38', 1,
10060 'P39', 1
10061 )
10062 )
10063 ),
10064 0, 'S',
10065 1, 'A'
10066 ),
10067 COUNT (DECODE (SUBSTR (bp.result_code, 1, 1), 'F', 1)), 'F',
10068 DECODE (DECODE (psa_bc_xla_pvt.g_bc_mode,
10069 'C', 'Y',
10070 'M', 'N',
10071 'P', 'Y',
10072 'N'
10073 ),
10074 'Y', 'P',
10075 'F'
10076 )
10077 )
10078 FROM gl_bc_packets bp
10079 WHERE bp.packet_id = p_packet_id AND bp.template_id IS NULL;
10080
10081 -- Bug 5397349 .. Start
10082 CURSOR c_get_result_codes (p_packet_id IN NUMBER) IS
10083 SELECT result_code, ae_header_id, ae_line_num
10084 FROM gl_bc_packets
10085 WHERE packet_id = p_packet_id;
10086
10087 TYPE result_code_tbl_type IS TABLE OF gl_bc_packets.result_code%type INDEX BY binary_integer;
10088 TYPE xla_hdr_tbl_type IS TABLE OF gl_bc_packets.ae_header_id%type INDEX BY binary_integer;
10089 TYPE xla_line_tbl_type IS TABLE OF gl_bc_packets.ae_line_num%type INDEX BY binary_integer;
10090
10091 l_result_code_tbl result_code_tbl_type;
10092 l_xla_hdr_tbl xla_hdr_tbl_type;
10093 l_xla_line_tbl xla_line_tbl_type;
10094 -- Bug 5397349 .. End
10095
10096 l_var_1 number;
10097 l_var_2 number;
10098 l_xla_hdr_status VARCHAR2(1);
10099 l_ae_lines_gt ae_lines_gt_rec;
10100 l_validation_lines_gt validation_lines_gt_rec;
10101 l_ledger_category gl_ledgers.ledger_category_code%type;
10102 l_event_cnt NUMBER;
10103 l_ae_event_cnt NUMBER;
10104
10105 -- Allocation Attributes related variables
10106 l_parent_trx c_get_parent_trx%ROWTYPE;
10107 l_child_trx c_get_child_trx%ROWTYPE;
10108 dummy VARCHAR2(100);
10109 l_alloc_used VARCHAR2(1);
10110 l_alloc_event_cnt NUMBER;
10111 l_xla_event_cnt NUMBER;
10112 l_parent_cnt NUMBER;
10113
10114 BEGIN
10115
10116 l_full_path := g_path || 'budgetary_control';
10117
10118 -- ====== FND LOG ======
10119 psa_utils.debug_other_string(g_state_level,l_full_path,
10120 ' BCTRL -> P_LEDGERID = '||p_ledgerid);
10121 psa_utils.debug_other_string(g_state_level,l_full_path,
10122 ' BCTRL -> MODE = '||PSA_BC_XLA_PVT.G_BC_MODE);
10123 psa_utils.debug_other_string(g_state_level,l_full_path,
10124 ' BCTRL -> OVERRIDE = '||PSA_BC_XLA_PVT.G_OVERRIDE_FLAG);
10125 psa_utils.debug_other_string(g_state_level,l_full_path,
10126 ' BCTRL -> USER_ID = '||PSA_BC_XLA_PVT.G_USER_ID);
10127 psa_utils.debug_other_string(g_state_level,l_full_path,
10128 ' BCTRL -> RESP_ID = '||PSA_BC_XLA_PVT.G_USER_RESP_ID);
10129 -- ====== FND LOG ======
10130 check_for_xla_errors ('BFLOW', l_xla_return_code);
10131 IF (l_xla_return_code = 'Y') THEN
10132 -- ====== FND LOG ======
10133 psa_utils.debug_other_string(g_error_level,l_full_path, ' BCTRL -> Bflow failed ');
10134 psa_utils.debug_other_string(g_error_level,l_full_path, ' BCTRL -> ERROR: FATAL ');
10135 -- ====== FND LOG ======
10136
10137 p_return_code := 'T';
10138 return FALSE;
10139 END IF;
10140
10141
10142 -- First invoke GLXFIN and assign values to global variables.
10143
10144 -- ====== FND LOG ======
10145 psa_utils.debug_other_string(g_state_level,l_full_path, ' BCTRL -> Invoking glxfin() ');
10146 -- ====== FND LOG ======
10147
10148 if not glxfin (p_ledgerid => p_ledgerid,
10149 p_packetid => 0,
10150 p_mode => PSA_BC_XLA_PVT.G_BC_MODE,
10151 p_override => PSA_BC_XLA_PVT.G_OVERRIDE_FLAG,
10152 p_conc_flag => 'N',
10153 p_user_id => PSA_BC_XLA_PVT.G_USER_ID,
10154 p_user_resp_id => PSA_BC_XLA_PVT.G_USER_RESP_ID,
10155 p_calling_prog_flag => 'S') then
10156
10157 -- ====== FND LOG ======
10158 psa_utils.debug_other_string(g_error_level,l_full_path, ' BCTRL -> glxfin failed ');
10159 psa_utils.debug_other_string(g_error_level,l_full_path, ' BCTRL -> ERROR: FATAL ');
10160 -- ====== FND LOG ======
10161
10162 p_return_code := 'T';
10163 return FALSE;
10164 end if;
10165
10166 -- Invoke the DEBUG_XLA procedure to transfer data from XLA global temporary tables to
10167 -- PSA regular tables.
10168
10169 debug_xla ( 'BUDGETARY_CONTROL_START' );
10170
10171 -- Check whether all the events in XLA_EVENTS_GT
10172 -- are available in XLA_AE_LINES_GT.
10173 /* If some events are missing that means that there is some issue in SLA
10174 setup for the event, that's why SLA didn't put that event to be
10175 considered for accounting. In this case Funds Checker API
10176 will treat this as an FATAL situation and will not process further. */
10177 OPEN c_cnt_events;
10178 FETCH c_cnt_events INTO l_event_cnt, l_ae_event_cnt;
10179 CLOSE c_cnt_events;
10180
10181 -- ====== FND LOG ======
10182 psa_utils.debug_other_string(g_error_level,l_full_path,
10183 ' BCTRL -> Count of events in XLA_EVENTS_GT: '||l_event_cnt);
10184 psa_utils.debug_other_string(g_error_level,l_full_path,
10185 ' BCTRL -> Count of events in XLA_AE_LINES_GT: '||l_ae_event_cnt);
10186 -- ====== FND LOG ======
10187
10188 fnd_file.put_line(fnd_file.log,'The following are the invalid accounting errrors');
10189 fnd_file.put_line(fnd_file.log,'=============================================== ');
10190 for acc_error in ( select document_reference , encoded_message
10191 from psa_bc_accounting_errors b
10192 where event_id in (select event_id from xla_events_gt))
10193 loop
10194 fnd_file.put_line(fnd_file.log , ' document_referece ' || acc_error.document_reference);
10195 fnd_file.put_line(fnd_file.log , acc_error.encoded_message);
10196 End loop;
10197
10198 IF NOT(NVL(l_ae_event_cnt, 0) = l_event_cnt) THEN
10199 -- ====== FND LOG ======
10200 psa_utils.debug_other_string(g_error_level,l_full_path, ' BCTRL -> Budgetary_Control failed ');
10201 psa_utils.debug_other_string(g_error_level,l_full_path, ' BCTRL -> ERROR: FATAL ');
10202 psa_utils.debug_other_string(g_error_level,l_full_path, ' BCTRL p_return_code -> T');
10203 psa_utils.debug_other_string(g_error_level,l_full_path, ' BCTRL Return False ');
10204
10205 check_for_xla_errors ('EVENTS_NOT_PROCESSED', l_xla_return_code);
10206
10207 fnd_file.put_line(fnd_file.log,'The following entities have not been processed');
10208 fnd_file.put_line(fnd_file.log,'======================================= ');
10209 for missing_entity in
10210 ( select e.entity_id,g.event_id,g.source_id_int_2,e.transaction_number
10211 from xla_transaction_entities_upg e , xla_events_gt g
10212 where g.entity_id = e.entity_id
10213 and g.event_id not in (select event_id from xla_ae_lines_gt) )
10214 loop
10215 fnd_file.put_line(fnd_file.log , ' BC_Event_id ' || missing_entity.event_id || ' Transaction Number ' || missing_entity.transaction_number || ' Distribution id ' || missing_entity.source_id_int_2 );
10216 end loop;
10217
10218
10219 -- ====== FND LOG ======
10220
10221 p_return_code := 'T';
10222 return FALSE;
10223 END IF;
10224
10225 -- Initialize the collection variables
10226
10227 -- ====== FND LOG ======
10228 psa_utils.debug_other_string(g_state_level,l_full_path, ' BCTRL -> Initializing collection ');
10229 -- ====== FND LOG ======
10230
10231 l_packets := num_rec();
10232
10233 -- Get the session_id and serial# for the current session
10234 -- These columns will then be inserted in gl_bc_packets.
10235
10236 -- ====== FND LOG ======
10237 psa_utils.debug_other_string(g_state_level,l_full_path, ' BCTRL -> Invoking get_session_details() ');
10238 -- ====== FND LOG ======
10239
10240 get_session_details(l_session_id, l_serial_id);
10241
10242 -- ====== FND LOG ======
10243 psa_utils.debug_other_string(g_state_level,l_full_path, ' BCTRL -> Session_Id = '||l_session_id);
10244 psa_utils.debug_other_string(g_state_level,l_full_path, ' BCTRL -> Serial_Id = '||l_serial_id);
10245 -- ====== FND LOG ======
10246
10247 -- Get the JE_SOURCE_NAME for current application
10248
10249 -- ====== FND LOG ======
10250 psa_utils.debug_other_string(g_state_level,l_full_path, ' BCTRL -> Get Je_Source_name ');
10251 -- ====== FND LOG ======
10252
10253 open get_je_source_name(PSA_BC_XLA_PVT.G_APPLICATION_ID);
10254 fetch get_je_source_name into l_je_source_name;
10255 if get_je_source_name%notfound then
10256 raise invalid_je_source_name;
10257 end if;
10258 close get_je_source_name;
10259
10260
10261 -- ====== FND LOG ======
10262 psa_utils.debug_other_string(g_state_level,l_full_path, ' BCTRL -> JE_SOURCE_NAME = '||l_je_source_name);
10263 -- ====== FND LOG ======
10264
10265 --================== Allocation Attributes first level of validation Logic Start ======================
10266 /* First level of validation for allocation attributes is two fold:
10267 1) We check whether transaction lines are related with allocation attributes or not.
10268 If allocation attributes are NOT used we do the normal processing.
10269 2) Using allocation attributes we find out the relationship amongst trx lines and
10270 store this information into PSA_BC_ALLOC_GT. Events stored in this table are sampled with
10271 events of XLA_PSA_BC_LINES_V. If any event is missing we disallow the group of related
10272 transaction rows to go in for funds operation. */
10273
10274 -- Preliminary check for allocation attributes usage.
10275 OPEN c_chk_alloc_used(p_ledgerid);
10276 FETCH c_chk_alloc_used INTO dummy;
10277
10278 IF c_chk_alloc_used%FOUND THEN
10279 CLOSE c_chk_alloc_used;
10280 l_alloc_used := 'Y';
10281 ELSE
10282 CLOSE c_chk_alloc_used;
10283 l_alloc_used := 'N';
10284 END IF;
10285
10286 --Resetting allocatons flag in case of prepay app
10287 --Bug#9840059
10288 IF (l_alloc_used = 'Y') THEN
10289 FOR check_prepay_rec IN (SELECT event_class_code
10290 FROM xla_events_gt
10291 WHERE event_class_code = 'PREPAYMENT APPLICATIONS') LOOP
10292 psa_utils.debug_other_string(g_state_level,l_full_path, 'Resetting l_alloc_used from Y to N');
10293 l_alloc_used := 'N';
10294 EXIT;
10295 END LOOP;
10296 END IF;
10297
10298 -- ====== FND LOG ======
10299 psa_utils.debug_other_string(g_state_level,l_full_path,
10300 ' BCTRL -> Allocation Attributes used (Y/N) = '||l_alloc_used);
10301 -- ====== FND LOG ======
10302
10303 IF (l_alloc_used = 'Y') THEN
10304 -- Initialize Parent counter;
10305 l_parent_cnt := 1;
10306 -- Find parent transactions;
10307 OPEN c_get_parent_trx;
10308 LOOP
10309 FETCH c_get_parent_trx INTO l_parent_trx;
10310 EXIT WHEN c_get_parent_trx%NOTFOUND;
10311 -- Find child transactions
10312 OPEN c_get_child_trx(l_parent_trx.ENTITY_CODE ,
10313 l_parent_trx.SOURCE_ID_INT_1 ,
10314 l_parent_trx.SOURCE_ID_INT_2 ,
10315 l_parent_trx.SOURCE_ID_INT_3 ,
10316 l_parent_trx.SOURCE_ID_INT_4 ,
10317 l_parent_trx.SOURCE_ID_CHAR_1 ,
10318 l_parent_trx.SOURCE_ID_CHAR_2 ,
10319 l_parent_trx.SOURCE_ID_CHAR_3 ,
10320 l_parent_trx.SOURCE_ID_CHAR_4 ,
10321 l_parent_trx.APPLICATION_ID,
10322 l_parent_trx.SOURCE_DISTRIBUTION_ID_NUM_1 ,
10323 l_parent_trx.SOURCE_DISTRIBUTION_ID_NUM_2 ,
10324 l_parent_trx.SOURCE_DISTRIBUTION_ID_NUM_3 ,
10325 l_parent_trx.SOURCE_DISTRIBUTION_ID_NUM_4 ,
10326 l_parent_trx.SOURCE_DISTRIBUTION_ID_NUM_5 ,
10327 l_parent_trx.SOURCE_DISTRIBUTION_TYPE,
10328 l_parent_trx.SOURCE_DISTRIBUTION_ID_CHAR_1 ,
10329 l_parent_trx.SOURCE_DISTRIBUTION_ID_CHAR_2 ,
10330 l_parent_trx.SOURCE_DISTRIBUTION_ID_CHAR_3 ,
10331 l_parent_trx.SOURCE_DISTRIBUTION_ID_CHAR_4 ,
10332 l_parent_trx.SOURCE_DISTRIBUTION_ID_CHAR_5
10333 );
10334 LOOP
10335 FETCH c_get_child_trx INTO l_child_trx;
10336 EXIT WHEN c_get_child_trx%NOTFOUND;
10337 -- now insert parent and child transactions in psa_bc_alloc_gt
10338 -- with a initial status of 'U' (Unprocessed)
10339 INSERT INTO psa_bc_alloc_gt (
10340 hierarchy_id,
10341 ae_header_id,
10342 ae_line_num,
10343 event_id,
10344 status_code
10345 ) VALUES (
10346 l_parent_cnt,
10347 l_child_trx.ae_header_id,
10348 l_child_trx.ae_line_num,
10349 l_child_trx.event_id,
10350 'U'
10351 );
10352 END LOOP;
10353 CLOSE c_get_child_trx;
10354 -- Increase the parent counter;
10355 l_parent_cnt := l_parent_cnt + 1;
10356 END LOOP;
10357 CLOSE c_get_parent_trx;
10358
10359 -- Now we will check that which hierarchy events should be
10360 -- allowed to go in funds checker by setting their
10361 -- status_code to 'P'(Passed) or 'F'(Failed)
10362 FOR h IN c_get_hierarchy_id
10363 LOOP
10364 SELECT
10365 COUNT(DISTINCT(event_id))
10366 INTO l_alloc_event_cnt
10367 FROM psa_bc_alloc_gt
10368 WHERE hierarchy_id = h.hierarchy_id;
10369
10370 -- ======================== FND LOG =============================
10371 psa_utils.debug_other_string(g_state_level, l_full_path, ' l_alloc_event_cnt -> '||l_alloc_event_cnt);
10372 -- ======================== FND LOG =============================
10373
10374 SELECT
10375 COUNT(DISTINCT(xv.event_id))
10376 INTO l_xla_event_cnt
10377 FROM xla_psa_bc_lines_v xv
10378 WHERE xv.event_id IN
10379 (
10380 (
10381 SELECT
10382 pa1.event_id
10383 FROM psa_bc_alloc_gt pa1
10384 WHERE pa1.hierarchy_id = h.hierarchy_id
10385 )
10386 MINUS
10387 (
10388 SELECT
10389 pa2.event_id
10390 FROM psa_bc_alloc_gt pa2
10391 WHERE pa2.event_id = xv.event_id
10392 AND pa2.status_code = 'F'
10393 )
10394 );
10395
10396 -- ======================== FND LOG =============================
10397 psa_utils.debug_other_string(g_state_level, l_full_path, ' l_xla_event_cnt -> '||l_xla_event_cnt);
10398 -- ======================== FND LOG =============================
10399
10400 -- Compare both the counts. if they are equal
10401 -- then the hierarchy events are eligible for funds check
10402 IF (l_alloc_event_cnt = NVL(l_xla_event_cnt, 0)) THEN
10403 UPDATE
10404 psa_bc_alloc_gt
10405 SET status_code = 'P'
10406 WHERE hierarchy_id = h.hierarchy_id;
10407 -- ====== FND LOG ======
10408 psa_utils.debug_other_string(g_state_level, l_full_path, ' BCTRL -> Updated '||sql%rowcount||
10409 ' rows.');
10410 -- ====== FND LOG ======
10411 ELSE
10412 UPDATE
10413 psa_bc_alloc_gt
10414 SET status_code = 'F'
10415 WHERE hierarchy_id = h.hierarchy_id;
10416 -- ====== FND LOG ======
10417 psa_utils.debug_other_string(g_state_level, l_full_path, ' BCTRL -> Updated '||sql%rowcount||
10418 ' rows.');
10419 -- ====== FND LOG ======
10420 END IF;
10421 END LOOP;
10422 END IF;
10423 --=================== Allocation Attributes first level of validation Logic End ===========================
10424
10425
10426 -- Now select the event_id and other information to be inserted
10427 -- in gl_bc_packets in plsql table. We will select all event_id
10428 -- to be inserted at one go for performance reasons. I have selected all columns
10429 -- from gl_bc_packets and put NULL for columns which should not be populated. This is to
10430 -- overcome a limitation with FORALL clause later in the code.
10431
10432
10433 -- ====== FND LOG ======
10434 psa_utils.debug_other_string(g_state_level,l_full_path, ' BCTRL -> Populate l_bc_pkts pl/sql table ');
10435 -- ====== FND LOG ======
10436
10437 SELECT NULL, -- Packet_id is initially NULL. Populated later in the code
10438 p_ledgerid, -- Since XLA view does not provide this column, use parameter
10439 nvl(l_je_source_name, 'Manual'),
10440 xv.je_category_name,
10441 xv.code_combination_id,
10442 xv.balance_type_code,
10443 xv.period_name,
10444 ps.period_year,
10445 ps.period_num,
10446 ps.quarter_num,
10447 xv.entered_currency_code,
10448 -- decode(psa_bc_xla_pvt.g_bc_mode, 'C', 'C', 'P'), Bug 6452856.
10449 decode(psa_bc_xla_pvt.g_bc_mode, 'C', 'C','M', 'C', 'P'),
10450 sysdate,
10451 g_user_id,
10452 xv.budget_version_id, -- BUDGET_VERSION_ID
10453 xv.encumbrance_type_id,
10454 NULL, -- TEMPLATE_ID
10455 xv.entered_dr,
10456 xv.entered_cr,
10457 xv.accounted_dr,
10458 xv.accounted_cr,
10459 NULL, -- USSGL_TRANSACTION_CODE
10460 NULL, -- ORIGINATING_ROWID
10461 NULL, -- ACCOUNT_SEGMENT_VALUE
10462 NULL, -- AUTOMATIC_ENCUMBRANCE_FLAG
10463 NULL, -- FUNDING_BUDGET_VERSION_ID
10464 NULL, -- FUNDS_CHECK_LEVEL_CODE
10465 NULL, -- AMOUNT_TYPE
10466 NULL, -- BOUNDARY_CODE
10467 NULL, -- TOLERANCE_PERCENTAGE
10468 NULL, -- TOLERANCE_AMOUNT
10469 NULL, -- OVERRIDE_AMOUNT
10470 NULL, -- DR_CR_CODE
10471 NULL, -- ACCOUNT_TYPE
10472 NULL, -- ACCOUNT_CATEGORY_CODE
10473 NULL, -- EFFECT_ON_FUNDS_CODE
10474 NULL, -- RESULT_CODE
10475 NULL, -- BUDGET_POSTED_BALANCE
10476 NULL, -- ACTUAL_POSTED_BALANCE
10477 NULL, -- ENCUMBRANCE_POSTED_BALANCE
10478 NULL, -- BUDGET_APPROVED_BALANCE
10479 NULL, -- ACTUAL_APPROVED_BALANCE
10480 NULL, -- ENCUMBRANCE_APPROVED_BALANCE
10481 NULL, -- BUDGET_PENDING_BALANCE
10482 NULL, -- ACTUAL_PENDING_BALANCE
10483 NULL, -- ENCUMBRANCE_PENDING_BALANCE
10484 NULL, -- REFERENCE1
10485 NULL, -- REFERENCE2
10486 NULL, -- REFERENCE3
10487 NULL, -- REFERENCE4
10488 NULL, -- REFERENCE5
10489 NULL, -- JE_BATCH_NAME
10490 -1, -- JE_BATCH_ID
10491 NULL, -- JE_HEADER_ID
10492 NULL, -- JE_LINE_NUM
10493 NULL, -- JE_LINE_DESCRIPTION
10494 NULL, -- REFERENCE6
10495 NULL, -- REFERENCE7
10496 NULL, -- REFERENCE8
10497 NULL, -- REFERENCE9
10498 NULL, -- REFERENCE10
10499 NULL, -- REFERENCE11
10500 NULL, -- REFERENCE12
10501 NULL, -- REFERENCE13
10502 NULL, -- REFERENCE14
10503 NULL, -- REFERENCE15
10504 NULL, -- REQUEST_ID
10505 NULL, -- USSGL_PARENT_ID
10506 NULL, -- USSGL_LINK_TO_PARENT_ID
10507 xv.event_id,
10508 xv.ae_header_id,
10509 xv.ae_line_num,
10510 NULL, -- BC_DATE
10511 xv.source_distribution_type,
10512 xv.source_distribution_id_char_1,
10513 xv.source_distribution_id_char_2,
10514 xv.source_distribution_id_char_3,
10515 xv.source_distribution_id_char_4,
10516 xv.source_distribution_id_char_5,
10517 xv.source_distribution_id_num_1,
10518 xv.source_distribution_id_num_2,
10519 xv.source_distribution_id_num_3,
10520 xv.source_distribution_id_num_4,
10521 xv.source_distribution_id_num_5,
10522 l_session_id,
10523 l_serial_id,
10524 psa_bc_xla_pvt.g_application_id,
10525 xv.entity_id,
10526 NULL -- GROUP_ID
10527 BULK COLLECT INTO l_bc_pkts
10528 FROM xla_psa_bc_lines_v xv,
10529 gl_period_statuses ps
10530 WHERE ps.ledger_id = p_ledgerid and
10531 xv.period_name = ps.period_name and
10532 ps.application_id = 101 and
10533 -- Bug 4778812 start
10534 (
10535 (l_alloc_used = 'Y' and
10536 xv.event_id IN (
10537 SELECT event_id
10538 FROM psa_bc_alloc_gt
10539 WHERE status_code = 'P')
10540 )
10541 OR
10542 (l_alloc_used = 'N')
10543 )
10544 -- Bug 4778812 end
10545 ORDER BY xv.entity_id, (nvl(entered_dr, 0)-nvl(entered_cr, 0)), source_distribution_id_num_1;
10546
10547 IF SQL%NOTFOUND THEN
10548
10549 check_for_xla_errors ('GL_BC_PACKETS_EMPTY', l_xla_return_code);
10550
10551 OPEN get_ledger_category(p_ledgerid);
10552 FETCH get_ledger_category INTO l_ledger_category;
10553 CLOSE get_ledger_category;
10554
10555 -- ====== FND LOG ======
10556 psa_utils.debug_other_string(g_state_level,l_full_path, ' BCTRL -> Ledger Category: '||l_ledger_category);
10557 psa_utils.debug_other_string(g_state_level,l_full_path, ' BCTRL -> Application Id: '||psa_bc_xla_pvt.g_application_id);
10558 -- ====== FND LOG ======
10559
10560 IF (l_ledger_category = 'PRIMARY') OR (psa_bc_xla_pvt.g_application_id = 602) THEN
10561 -- ==================== FND LOG ===========================
10562 psa_utils.debug_other_string(g_state_level,l_full_path, ' l_ledger_category = PRIMARY OR (psa_bc_xla_pvt.g_application_id = 602 --> raise gl_bc_packets_empty');
10563 -- ==================== FND LOG ===========================
10564
10565 raise gl_bc_packets_empty;
10566 ELSE
10567
10568 -- ====== FND LOG ======
10569 psa_utils.debug_other_string(g_state_level,l_full_path, ' BCTRL -> Do not process for Secondary Ledger ');
10570 psa_utils.debug_other_string(g_state_level,l_full_path, ' BCTRL -> Return True');
10571 psa_utils.debug_other_string(g_state_level,l_full_path, ' BCTRL p_return_code -> S ');
10572 -- ====== FND LOG ======
10573 p_return_code := 'S';
10574 return true;
10575 END IF;
10576
10577 ELSE
10578
10579 -- ====== FND LOG ======
10580 psa_utils.debug_other_string(g_state_level,l_full_path, ' BCTRL -> Populated '||sql%rowcount||' rows. ');
10581 -- ====== FND LOG ======
10582 END IF;
10583
10584 -- Note above that the packet_id column was assigned a NULL value.
10585 -- Since packet_id will be unique per entity_id, we will use the
10586 -- following plsql logic to assign packet_id for each row above.
10587 -- Logic: Check if this is the first packet_id to be processed.
10588 -- If First_Packet_id then => assign new packet_id
10589 -- Elsif (Current Entity Id <> Previous Entity Id) then => assign new packet_id
10590 -- Else assign earlier packet_id.
10591
10592 FOR x in 1..l_bc_pkts.count
10593 LOOP
10594
10595 if (x = 1) then
10596 l_packet_id := get_packet_id;
10597 l_packets.extend(1);
10598 l_packets(l_packets.count) := l_packet_id;
10599 elsif (l_bc_pkts(x).entity_id <> l_bc_pkts(x-1).entity_id) then
10600 l_packet_id := get_packet_id;
10601 l_packets.extend(1);
10602 l_packets(l_packets.count) := l_packet_id;
10603 end if;
10604
10605 l_bc_pkts(x).packet_id := l_packet_id;
10606
10607 -- ====== FND LOG ======
10608 psa_utils.debug_other_string(g_state_level,l_full_path, ' BCTRL -> Row '||x||' assigned packet_id '||l_packet_id);
10609 -- ====== FND LOG ======
10610
10611 END LOOP;
10612
10613 -- Insert autonomous procedure populate_bc_pkts to insert data in gl_bc_packets
10614
10615 -- ====== FND LOG ======
10616 psa_utils.debug_other_string(g_state_level,l_full_path, ' BCTRL -> Invoking populate_bc_pkts() ');
10617 -- ====== FND LOG ======
10618
10619 IF NOT populate_bc_pkts (l_bc_pkts) THEN
10620 -- ====== FND LOG ======
10621 psa_utils.debug_other_string(g_error_level,l_full_path, ' BCTRL -> populate_bc_pkts() failed. ');
10622 psa_utils.debug_other_string(g_error_level,l_full_path, ' BCTRL -> ERROR: FATAL. ');
10623 psa_utils.debug_other_string(g_error_level,l_full_path, ' BCTRL -> p_return_code -> T');
10624 psa_utils.debug_other_string(g_error_level,l_full_path, ' BCTRL -> Return false ');
10625 -- ====== FND LOG ======
10626 p_return_code := 'T';
10627 return FALSE;
10628 END IF;
10629
10630 -- Invoke funds checker per packet_id. Update the relevant SLA tables.
10631
10632 -- ====== FND LOG ======
10633 psa_utils.debug_other_string(g_state_level,l_full_path, ' BCTRL -> Invoking glxfck() per packet.');
10634 -- ====== FND LOG ======
10635
10636 FOR i IN 1..l_packets.count
10637 LOOP
10638
10639 -- ====== FND LOG ======
10640 psa_utils.debug_other_string(g_state_level,l_full_path,
10641 ' BCTRL -> Invoking glxfck() for packet_id '||l_packets(i));
10642 -- ====== FND LOG ======
10643
10644 IF NOT glxfck( p_ledgerid ,
10645 l_packets(i) ,
10646 PSA_BC_XLA_PVT.G_BC_MODE ,
10647 PSA_BC_XLA_PVT.G_OVERRIDE_FLAG ,
10648 'N' ,
10649 PSA_BC_XLA_PVT.G_USER_ID ,
10650 PSA_BC_XLA_PVT.G_USER_RESP_ID ,
10651 'S' ,
10652 l_ret_code ) THEN
10653
10654 -- ====== FND LOG ======
10655 psa_utils.debug_other_string(g_state_level,l_full_path, ' BCTRL -> glxfck() failed ');
10656 -- ====== FND LOG ======
10657
10658 -- ============================== FND LOG =========================
10659 psa_utils.debug_other_string(g_state_level,l_full_path, ' BCTRL l_ret_code -> T ');
10660 -- ============================== FND LOG =========================
10661
10662 l_ret_code := 'T';
10663 END IF;
10664
10665 -- Update Funds_Status_Code column in XLA_AE_HEADERS_GT
10666
10667 -- ====== FND LOG ======
10668 psa_utils.debug_other_string(g_state_level, l_full_path, ' BCTRL -> Update funds_status_code '||
10669 'of xla_ae_headers_gt ');
10670 -- ====== FND LOG ======
10671
10672 IF (PSA_BC_XLA_PVT.G_BC_MODE = 'P') AND (l_ret_code <> 'T') THEN
10673 FOR y IN get_status_per_header(l_packets(i))
10674 LOOP
10675 -- ====== FND LOG ======
10676 psa_utils.debug_other_string(g_state_level,l_full_path, ' BCTRL -> GET_STATUS_PER_HEADER DETAILS ');
10677 psa_utils.debug_other_string(g_state_level,l_full_path, ' BCTRL -> ----------------------------- ');
10678 psa_utils.debug_other_string(g_state_level,l_full_path, ' BCTRL -> Y.AE_HEADER_ID = '||y.ae_header_id);
10679 psa_utils.debug_other_string(g_state_level,l_full_path, ' BCTRL -> Y.SUCCESS_CNT = '||y.success_cnt);
10680 psa_utils.debug_other_string(g_state_level,l_full_path, ' BCTRL -> Y.APPROVED_CNT = '||y.approved_cnt);
10681 psa_utils.debug_other_string(g_state_level,l_full_path, ' BCTRL -> Y.FAILED_CNT = '||y.failed_cnt);
10682 psa_utils.debug_other_string(g_state_level,l_full_path, ' BCTRL -> Y.REJECTED_CNT = '||y.rejected_cnt);
10683 psa_utils.debug_other_string(g_state_level,l_full_path, ' BCTRL -> Y.TOTAL_CNT = '||y.total_cnt);
10684 -- ====== FND LOG ======
10685
10686 IF (y.success_cnt = y.total_cnt) OR (y.approved_cnt = y.total_cnt) THEN
10687 SELECT nvl(min('A'), 'S') into l_xla_hdr_status
10688 FROM gl_bc_packets
10689 WHERE packet_id = l_packets(i) and
10690 ae_header_id = y.ae_header_id and
10691 result_code IN ('P20', 'P22', 'P25', 'P27', 'P31', 'P35', 'P36', 'P37',
10692 'P38', 'P39');
10693 ELSIF (y.failed_cnt = y.total_cnt) OR (y.rejected_cnt = y.total_cnt) THEN
10694 l_xla_hdr_status := 'F';
10695 ELSE
10696 l_xla_hdr_status := 'P';
10697 END IF;
10698
10699 -- ============================== FND LOG =========================
10700 psa_utils.debug_other_string(g_state_level,l_full_path, ' BCTRL l_xla_hdr_status -> '||l_xla_hdr_status);
10701 -- ============================== FND LOG =========================
10702
10703 UPDATE xla_ae_headers_gt
10704 SET funds_status_code = l_xla_hdr_status
10705 WHERE ae_header_id = y.ae_header_id and
10706 ledger_id = p_ledgerid;
10707
10708 IF SQL%FOUND THEN
10709 -- ====== FND LOG ======
10710 psa_utils.debug_other_string(g_state_level, l_full_path, ' BCTRL -> XLA Header '||y.ae_header_id||
10711 ', Status updated to '||l_xla_hdr_status);
10712 -- ====== FND LOG ======
10713 END IF;
10714
10715 END LOOP;
10716 ELSE
10717 UPDATE xla_ae_headers_gt
10718 SET funds_status_code = l_ret_code
10719 WHERE ae_header_id IN (SELECT ae_header_id
10720 FROM gl_bc_packets
10721 WHERE packet_id = l_packets(i)) and
10722 ledger_id = p_ledgerid;
10723
10724 -- ====== FND LOG ======
10725 psa_utils.debug_other_string(g_state_level, l_full_path, ' BCTRL -> Updated funds_status_code of '||
10726 sql%rowcount||' rows successfully. ');
10727 -- ====== FND LOG ======
10728 END IF;
10729
10730 -- Update the l_*_status_cnt variables.
10731
10732 IF (l_ret_code IN ('S','A')) THEN
10733 l_s_status_cnt := nvl(l_s_status_cnt, 0) + 1;
10734 ELSIF (l_ret_code = 'F') THEN
10735 l_f_status_cnt := nvl(l_f_status_cnt, 0) + 1;
10736 ELSIF (l_ret_code = 'P') THEN
10737 l_p_status_cnt := nvl(l_p_status_cnt, 0) + 1;
10738 ELSIF (l_ret_code = 'T') OR (l_ret_code IS NULL) THEN
10739 l_t_status_cnt := nvl(l_t_status_cnt, 0) + 1;
10740 END IF;
10741
10742 END LOOP;
10743
10744 -- Update Funds_Status_Code column in XLA_VALIDATION_LINES_GT
10745
10746 -- ====== FND LOG ======
10747 psa_utils.debug_other_string(g_state_level, l_full_path, ' BCTRL -> Update funds_status_code '||
10748 'of xla_validation_lines_gt');
10749 -- ====== FND LOG ======
10750
10751 -- Bug 5397349 .. Start
10752
10753 FOR i IN 1..l_packets.count
10754 LOOP
10755
10756 OPEN c_get_result_codes (l_packets(i));
10757
10758 LOOP
10759 FETCH c_get_result_codes bulk collect into l_result_code_tbl, l_xla_hdr_tbl, l_xla_line_tbl LIMIT 5000;
10760
10761 FORALL x IN 1..l_result_code_tbl.count
10762 UPDATE xla_validation_lines_gt vl
10763 SET vl.funds_status_code = l_result_code_tbl(x)
10764 WHERE vl.ae_header_id = l_xla_hdr_tbl(x) AND
10765 vl.ae_line_num = l_xla_line_tbl(x) AND
10766 vl.ledger_id = p_ledgerid;
10767
10768 -- ====== FND LOG ======
10769 psa_utils.debug_other_string(g_state_level, l_full_path, ' BCTRL -> Updated '||sql%rowcount||
10770 ' rows.');
10771 -- ====== FND LOG ======
10772
10773 EXIT when c_get_result_codes%notfound;
10774 END LOOP;
10775
10776 CLOSE c_get_result_codes;
10777 END LOOP;
10778
10779 -- Bug 5397349 .. End
10780
10781 -- Update PSA_BC_XLA_EVENTS_GT table with result_code
10782
10783 -- ====== FND LOG ======
10784 psa_utils.debug_other_string(g_state_level, l_full_path, ' BCTRL -> Update result_code '||
10785 'of psa_bc_xla_events_gt');
10786 -- ====== FND LOG ======
10787
10788 -- this update will ensure that only valid xla events
10789 -- provided for FUNDS CHECK (meant xla_ae_headers rows updated with funds_status_code)
10790 -- are updated with appropiate status. Events NOT picked by funds checker will be updated with XLA_ERROR.
10791 UPDATE psa_bc_xla_events_gt eg
10792 SET result_code = (SELECT decode(min(funds_status_code),
10793 'T', 'FATAL',
10794 'S', 'SUCCESS',
10795 'A', 'ADVISORY',
10796 'F', 'FAIL',
10797 'P', 'PARTIAL',
10798 'XLA_ERROR')
10799 FROM xla_ae_headers_gt hg
10800 WHERE hg.event_id = eg.event_id)
10801 where eg.event_id in (select event_id from xla_ae_headers_gt);
10802
10803 -- ====== FND LOG ======
10804 psa_utils.debug_other_string(g_state_level, l_full_path, ' BCTRL -> Updated valid funds check '||sql%rowcount||
10805 ' rows.');
10806 -- ====== FND LOG ======
10807
10808 -- Update global variable for packet_id to the first packet_id
10809
10810 PSA_BC_XLA_PVT.G_PACKET_ID := l_packets(1);
10811
10812 -- ====== FND LOG ======
10813 psa_utils.debug_other_string(g_state_level, l_full_path, ' BCTRL -> Updated '||
10814 ' PSA_BC_XLA_PVT.G_PACKET_ID to '||PSA_BC_XLA_PVT.G_PACKET_ID);
10815 -- ====== FND LOG ======
10816
10817 -- ====== FND LOG ======
10818 psa_utils.debug_other_string(g_state_level, l_full_path, ' BCTRL -> l_t_status_cnt = '||l_t_status_cnt);
10819 psa_utils.debug_other_string(g_state_level, l_full_path, ' BCTRL -> l_s_status_cnt = '||l_s_status_cnt);
10820 psa_utils.debug_other_string(g_state_level, l_full_path, ' BCTRL -> l_a_status_cnt = '||l_a_status_cnt);
10821 psa_utils.debug_other_string(g_state_level, l_full_path, ' BCTRL -> l_f_status_cnt = '||l_f_status_cnt);
10822 psa_utils.debug_other_string(g_state_level, l_full_path, ' BCTRL -> l_p_status_cnt = '||l_p_status_cnt);
10823 -- ====== FND LOG ======
10824
10825 -- Bug 4918234
10826 /* We need to update the related events stauses which were NOT picked up by funds checker.
10827 e.g. PA BURDEN lines failed XLA validation but corresponding PO RAW passed XLA validation
10828 or PO RAW line failed XLA validation but corresponding PA BURDEN lines passed XLA validation.
10829 */
10830
10831 -- Update Funds_Status_Code column in XLA_AE_HEADERS_GT
10832 UPDATE xla_ae_headers_gt
10833 SET funds_status_code = 'F'
10834 WHERE event_id IN (
10835 SELECT event_id
10836 FROM psa_bc_alloc_gt
10837 WHERE status_code <> 'P');
10838
10839 IF(SQL%ROWCOUNT<> 0) THEN
10840 -- ====== FND LOG ======
10841 psa_utils.debug_other_string(g_state_level,l_full_path, ' BCTRL -> Updated '||sql%rowcount||' rows of XLA_AE_HEADERS_GT with fail status.');
10842 -- ====== FND LOG ======
10843 END IF;
10844
10845 -- Update Funds_Status_Code column in XLA_VALIDATION_LINES_GT
10846 UPDATE xla_validation_lines_gt vl
10847 SET vl.funds_status_code = 'F76'
10848 WHERE event_id IN (
10849 SELECT event_id
10850 FROM psa_bc_alloc_gt
10851 WHERE status_code <> 'P');
10852
10853 IF(SQL%ROWCOUNT<> 0) THEN
10854 -- ====== FND LOG ======
10855 psa_utils.debug_other_string(g_state_level, l_full_path, ' BCTRL -> Updated ' ||sql%rowcount||' rows of XLA_VALIDATION_LINES_GT with F76 status code.');
10856 -- ====== FND LOG ======
10857 END IF;
10858
10859 --================== Allocation Attributes second level of validation Logic start =================
10860 /* Now we need to check that the transaction rows which are put for funds operation,
10861 have been successfully processed by funds checker. If atleast one transaction row
10862 for a hierarchy fails funds operation, we will fail all the related transaction rows in
10863 GL_BC_PACKETS with the status F77. */
10864
10865 IF (l_alloc_used = 'Y') THEN
10866 FOR h in c_get_hierarchy_id
10867 LOOP
10868 OPEN c_chk_funds_hier(h.hierarchy_id,
10869 l_session_id,
10870 l_serial_id);
10871 FETCH c_chk_funds_hier INTO dummy;
10872 IF (c_chk_funds_hier%FOUND) THEN
10873 CLOSE c_chk_funds_hier;
10874 -- update the statuses of gl_bc_packets
10875 -- related rows to 'F' Failed or 'R' Rejected.
10876 UPDATE gl_bc_packets
10877 SET status_code = decode(PSA_BC_XLA_PVT.G_BC_MODE, 'C', 'F',
10878 'M', 'F',
10879 'R', 'R',
10880 'P', 'R')
10881 ,result_code = 'F77'
10882 WHERE (ae_header_id, ae_line_num, event_id)
10883 IN (SELECT ae_header_id, ae_line_num, event_id
10884 FROM psa_bc_alloc_gt
10885 WHERE hierarchy_id = h.hierarchy_id
10886 )
10887 AND status_code NOT IN ('F', 'R')
10888 AND session_id = l_session_id
10889 AND serial_id = l_serial_id;
10890 -- ====== FND LOG ======
10891 psa_utils.debug_other_string(g_state_level, l_full_path, 'BCTRL -> Updated '
10892 ||sql%rowcount||' rows of GL_BC_PACKETS with F77 status.');
10893 -- ====== FND LOG ======
10894
10895 ELSE
10896 CLOSE c_chk_funds_hier;
10897 END IF;
10898 END LOOP;
10899
10900 UPDATE xla_ae_headers_gt
10901 SET funds_status_code = decode(PSA_BC_XLA_PVT.G_BC_MODE, 'C', 'F',
10902 'M', 'F',
10903 'R', 'F',
10904 'P', 'F')
10905 WHERE ae_header_id IN (SELECT ae_header_id
10906 FROM gl_bc_packets
10907 WHERE result_code = 'F77'
10908 AND session_id = l_session_id
10909 AND serial_id = l_serial_id) and
10910 ledger_id = p_ledgerid;
10911 -- ====== FND LOG ======
10912 psa_utils.debug_other_string(g_state_level, l_full_path, ' BCTRL -> Updated funds_status_code of '||
10913 sql%rowcount||' rows successfully of XLA_AE_HEADERS_GT. ');
10914 -- ====== FND LOG ======
10915
10916 UPDATE xla_validation_lines_gt vl
10917 SET vl.funds_status_code = 'F77'
10918 WHERE vl.ae_header_id IN (SELECT ae_header_id
10919 FROM gl_bc_packets
10920 WHERE result_code = 'F77'
10921 AND session_id = l_session_id
10922 AND serial_id = l_serial_id) and
10923 vl.ledger_id = p_ledgerid;
10924 -- ====== FND LOG ======
10925 psa_utils.debug_other_string(g_state_level, l_full_path, ' BCTRL -> Updated '||sql%rowcount||
10926 ' rows of XLA_VALIDATION_LINES_GT with F77 status.');
10927 -- ====== FND LOG ======
10928
10929 -- Reinitialize all the count variables
10930 l_s_status_cnt := 0;
10931 l_a_status_cnt := 0;
10932 l_f_status_cnt := 0;
10933 l_p_status_cnt := 0;
10934 l_t_status_cnt := 0;
10935 l_ret_code := NULL;
10936
10937 -- Now for each packet evaluate the return_code
10938 FOR i IN 1..l_packets.COUNT
10939 LOOP
10940 OPEN c_pkt_retcode(l_packets(i));
10941 FETCH c_pkt_retcode INTO l_ret_code;
10942 CLOSE c_pkt_retcode;
10943 IF (l_ret_code IN ('S', 'A')) THEN
10944 l_s_status_cnt := nvl(l_s_status_cnt, 0) + 1;
10945 ELSIF (l_ret_code = 'F') THEN
10946 l_f_status_cnt := nvl(l_f_status_cnt, 0) + 1;
10947 ELSIF (l_ret_code = 'P') THEN
10948 l_p_status_cnt := nvl(l_p_status_cnt, 0) + 1;
10949 ELSIF (l_ret_code = 'T') OR (l_ret_code IS NULL) THEN
10950 l_t_status_cnt := nvl(l_t_status_cnt, 0) + 1;
10951 END IF;
10952 l_ret_code := NULL;
10953 END LOOP;
10954
10955 END IF;
10956
10957 --================== Allocation Attributes second level of validation Logic end =================
10958
10959 -- Set the return code
10960 IF nvl(l_t_status_cnt , 0) > 0 THEN
10961 p_return_code := 'T';
10962 ELSIF (nvl(l_p_status_cnt, 0) > 0) OR (nvl(l_f_status_cnt, 0) > 0 AND nvl(l_s_status_cnt, 0) > 0) THEN
10963 p_return_code := 'P';
10964 ELSIF nvl(l_f_status_cnt, 0) > 0 THEN
10965 p_return_code := 'F';
10966 ELSE
10967 p_return_code := 'S';
10968 END IF;
10969
10970 -- ====== FND LOG ======
10971 psa_utils.debug_other_string(g_state_level, l_full_path, ' BCTRL -> Return_code = '||p_return_code);
10972 psa_utils.debug_other_string(g_state_level, l_full_path, ' BCTRL -> Return TRUE');
10973 -- ====== FND LOG ======
10974
10975 -- Invoke the DEBUG_XLA procedure to transfer data from XLA global temporary tables to
10976 -- PSA regular tables.
10977
10978 debug_xla ( 'BUDGETARY_CONTROL_END' );
10979
10980 psa_utils.debug_other_string(g_state_level,l_full_path,'Cleaning up psa_bc_alloc_gt Table');
10981 DELETE FROM psa_bc_alloc_gt; --For bug 7607496
10982 psa_utils.debug_other_string(g_state_level,l_full_path, ' Deleted Rows -> ' || SQL%ROWCOUNT);
10983
10984 return TRUE;
10985
10986 EXCEPTION
10987 WHEN GL_BC_PACKETS_EMPTY THEN
10988 IF (NOT g_xla_debug) THEN
10989 -- ====== FND LOG ======
10990 psa_utils.debug_other_string(g_error_level,l_full_path, ' BCTRL -> XLA_AE_HEADERS_GT DUMP');
10991 psa_utils.debug_other_string(g_error_level,l_full_path, ' -------------------- ');
10992
10993 -- ====== FND LOG ======
10994 FOR h IN debug_xla_ae_headers_gt
10995 LOOP
10996 -- ====== FND LOG ======
10997 psa_utils.debug_other_string(g_error_level,l_full_path, ' EVENT_ID = '||h.event_id||' , '||
10998 ' AE_HEADER_ID = '||h.ae_header_id||' , '||
10999 ' LEDGER_ID = '||h.ledger_id||' , '||
11000 ' EVENT_TYPE_CODE = '||h.event_type_code||' , '||
11001 ' FUNDS_STATUS_CODE = '||h.funds_status_code||' , '||
11002 ' ACCOUNTING_ENTRY_STATUS_CODE = '||h.accounting_entry_status_code||' , '||
11003 ' BALANCE_TYPE_CODE = '||h.balance_type_code);
11004 -- ====== FND LOG ======
11005 END LOOP;
11006 -- ====== FND LOG ======
11007 psa_utils.debug_other_string(g_error_level,l_full_path, ' BCTRL -> XLA_AE_LINES_GT DUMP');
11008 psa_utils.debug_other_string(g_error_level,l_full_path, ' -------------------- ');
11009
11010
11011 -- ====== FND LOG ======
11012 FOR x IN debug_xla_ae_lines_gt
11013 LOOP
11014 -- ====== FND LOG ======
11015 psa_utils.debug_other_string(g_error_level,l_full_path, ' EVENT_ID = '||x.event_id||' , '||
11016 ' AE_HEADER_ID = '||x.ae_header_id||' , '||
11017 ' AE_LINE_NUM = '||x.ae_line_num);
11018 -- ====== FND LOG ======
11019 END LOOP;
11020
11021 -- ====== FND LOG ======
11022 psa_utils.debug_other_string(g_error_level,l_full_path, ' BCTRL -> XLA_VALIDATION_LINES_GT DUMP');
11023 psa_utils.debug_other_string(g_error_level,l_full_path, ' ---------------------------- ');
11024 -- ====== FND LOG ======
11025 FOR y IN debug_xla_val_lines_gt
11026 LOOP
11027 -- ====== FND LOG ======
11028 psa_utils.debug_other_string(g_error_level,l_full_path, ' AE_HEADER_ID = '||y.ae_header_id||' , '||
11029 ' AE_LINE_NUM = '||y.ae_line_num||' , '||
11030 ' PERIOD_NAME = '||y.period_name||' , '||
11031 ' ACCOUNTING_ENTRY_STATUS_CODE = '||y.accounting_entry_status_code||' , '||
11032 ' BALANCING_LINE_TYPE = '||y.balancing_line_type);
11033 -- ====== FND LOG ======
11034 END LOOP;
11035
11036 -- ====== FND LOG ======
11037 psa_utils.debug_other_string(g_error_level,l_full_path, ' BCTRL -> XLA_EVENTS_GT DUMP');
11038 psa_utils.debug_other_string(g_error_level,l_full_path, ' ---------------------------- ');
11039 -- ====== FND LOG ======
11040 FOR z in debug_xla_events_gt
11041 LOOP
11042 -- ====== FND LOG ======
11043 psa_utils.debug_other_string(g_error_level,l_full_path, ' APPLICATION_ID = '||z.application_id||' , '||
11044 ' EVENT_ID = '||z.event_id||' , '||
11045 ' EVENT_DATE = '||z.event_date||' , '||
11046 ' EVENT_TYPE_CODE = '||z.event_type_code||' , '||
11047 ' REFERENCE_NUM_1 = '||z.reference_num_1);
11048 -- ====== FND LOG ======
11049 END LOOP;
11050 -- ====== FND LOG ======
11051 psa_utils.debug_other_string(g_error_level,l_full_path, ' BCTRL -> XLA_PSA_BC_LINES_V DUMP');
11052 psa_utils.debug_other_string(g_error_level,l_full_path,' --------------------------------------- ');
11053 -- ====== FND LOG ======
11054 FOR v in debug_xla_psa_bc_v
11055 LOOP
11056 -- ====== FND LOG ======
11057 psa_utils.debug_other_string(g_error_level,l_full_path, ' EVENT_ID = '||v.event_id||' , '||
11058 ' AE_HEADER_ID = '||v.ae_header_id||' , '||
11059 ' AE_LINE_NUM = '||v.ae_line_num||' , '||
11060 ' ENTITY_ID = '||v.entity_id||' , '||
11061 ' PERIOD_NAME = '||v.period_name);
11062 -- ====== FND LOG ======
11063 END LOOP;
11064
11065 -- ====== FND LOG ======
11066 psa_utils.debug_other_string(g_error_level,l_full_path, ' BCTRL -> PSA_BC_ALLOC_GT DUMP');
11067 psa_utils.debug_other_string(g_error_level,l_full_path,' --------------------------------------- ');
11068 -- ====== FND LOG ======
11069 FOR p in debug_psa_bc_alloc_gt
11070 LOOP
11071 -- ====== FND LOG ======
11072 psa_utils.debug_other_string(g_error_level,l_full_path, ' HIERARCHY_ID = '||p.hierarchy_id||' , '||
11073 ' EVENT_ID = '||p.event_id||' , '||
11074 ' AE_HEADER_ID = '||p.ae_header_id||' , '||
11075 ' AE_LINE_NUM = '||p.ae_line_num||' , '||
11076 ' STATUS_CODE = '||p.status_code);
11077 -- ====== FND LOG ======
11078 END LOOP;
11079
11080
11081 select count(*) into l_var_1
11082 from xla_psa_bc_lines_v;
11083 -- ====== FND LOG ======
11084 psa_utils.debug_other_string(g_error_level,l_full_path, ' XLA_PSA_BC_LINES_V returns '||l_var_1||' rows. ');
11085 psa_utils.debug_other_string(g_error_level,l_full_path, ' Error: Populated 0 rows in gl_bc_packets.');
11086 psa_utils.debug_other_string(g_error_level,l_full_path, ' RETURN -> FALSE');
11087 -- ====== FND LOG ======
11088 END IF;
11089 p_return_code := 'T';
11090 return FALSE;
11091 WHEN OTHERS THEN
11092 -- ====== FND LOG ======
11093 psa_utils.debug_other_string(g_excep_level, l_full_path, ' BCTRL -> Exception Raised: '||sqlerrm);
11094 psa_utils.debug_other_string(g_excep_level, l_full_path, ' BCTRL -> Return_code = T');
11095 psa_utils.debug_other_string(g_excep_level, l_full_path, ' BCTRL -> Return FALSE');
11096 -- ====== FND LOG ======
11097 p_return_code := 'T';
11098 return FALSE;
11099
11100 END budgetary_control;
11101
11102 /*===========================================================================================+
11103 | Procedure : SYNC_XLA_ERRORS |
11104 | Description : This API is invoked by SLA in package |
11105 | XLA_JE_VALIDATION_PKG.UNDO_FUNDS_RESERVE to synchronize budgetary control |
11106 | errors in secondary/reporting ledgers reported by SLA. |
11107 +===========================================================================================*/
11108
11109 PROCEDURE sync_xla_errors (p_failed_ldgr_array IN num_rec,
11110 p_failed_evnt_array IN num_rec)
11111 IS
11112
11113
11114 CURSOR c_success_evt_exists IS
11115 SELECT 'Successful event exists in the current packet'
11116 FROM gl_bc_packets
11117 WHERE event_id IN (SELECT event_id
11118 FROM psa_bc_xla_events_gt
11119 )
11120 AND application_id = PSA_BC_XLA_PVT.g_application_id
11121 AND status_code = 'A';
11122
11123 dummy VARCHAR2(100);
11124 l_success_evt_exist VARCHAR2(1);
11125 l_f81_cnt NUMBER;
11126 l_f82_cnt NUMBER;
11127
11128 -- ========================= FND LOG ===========================
11129 l_full_path VARCHAR2(100);
11130 -- ========================= FND LOG ===========================
11131
11132 BEGIN
11133
11134 l_f81_cnt := 0;
11135 l_f82_cnt := 0;
11136 l_full_path := g_path || 'sync_xla_errors';
11137
11138 -- ====== FND LOG ======
11139 psa_utils.debug_other_string(g_state_level, l_full_path, ' BCTRL -> p_failed_ldgr_array.COUNT: '|| p_failed_ldgr_array.COUNT);
11140 psa_utils.debug_other_string(g_state_level, l_full_path, ' BCTRL -> p_failed_evnt_array.COUNT: '|| p_failed_evnt_array.COUNT);
11141 -- ====== FND LOG ======
11142
11143 FORALL i IN 1..p_failed_ldgr_array.COUNT
11144 UPDATE gl_bc_packets
11145 SET status_code = decode(PSA_BC_XLA_PVT.G_BC_MODE, 'C', 'F',
11146 'M', 'F',
11147 'R', 'R',
11148 'P', 'R')
11149 ,result_code = 'F81'
11150 WHERE event_id = p_failed_evnt_array(i)
11151 AND application_id = PSA_BC_XLA_PVT.g_application_id
11152 AND ledger_id = p_failed_ldgr_array(i)
11153 AND status_code NOT IN ('F', 'R');
11154
11155 l_f81_cnt := SQL%ROWCOUNT;
11156
11157 -- ====== FND LOG ======
11158 psa_utils.debug_other_string(g_state_level, l_full_path, ' BCTRL -> Updated GL_BC_PACKETS '||l_f81_cnt||
11159 ' rows to F81 status.');
11160 -- ====== FND LOG ======
11161
11162
11163 FORALL j IN 1..p_failed_evnt_array.COUNT
11164 UPDATE gl_bc_packets
11165 SET status_code = decode(PSA_BC_XLA_PVT.G_BC_MODE, 'C', 'F',
11166 'M', 'F',
11167 'R', 'R',
11168 'P', 'R')
11169 ,result_code = 'F82'
11170 WHERE event_id = p_failed_evnt_array(j)
11171 AND application_id = PSA_BC_XLA_PVT.g_application_id
11172 AND status_code NOT IN ('F', 'R');
11173
11174 l_f82_cnt := SQL%ROWCOUNT;
11175
11176 -- ====== FND LOG ======
11177 psa_utils.debug_other_string(g_state_level, l_full_path, ' BCTRL -> Updated GL_BC_PACKETS '||l_f82_cnt||
11178 ' rows to F82 status.');
11179 -- ====== FND LOG ======
11180
11181 -- This check is to ensure that if we have not updated any GL_BC_PACKETS
11182 -- row/s to failure then there was a genuine failure in GL_BC_PACKETS
11183 -- and we should not overwrite that failure with XLA_ERROR for the event.
11184 -- We need to retain the original failure status reported and inform the same
11185 -- back to the calling transaction.
11186
11187 IF (l_f81_cnt <> 0 OR l_f82_cnt <> 0) THEN
11188 FORALL k IN 1..p_failed_evnt_array.COUNT
11189 UPDATE psa_bc_xla_events_gt
11190 SET result_code = 'XLA_ERROR'
11191 WHERE event_id = p_failed_evnt_array(k)
11192 AND result_code <> 'XLA_ERROR';
11193
11194 -- ====== FND LOG ======
11195 psa_utils.debug_other_string(g_state_level, l_full_path, ' BCTRL -> Updated PSA_BC_XLA_EVENTS_GT '||sql%rowcount||
11196 ' rows to XLA_ERROR status.');
11197 -- ====== FND LOG ======
11198
11199 END IF;
11200
11201 OPEN c_success_evt_exists;
11202 FETCH c_success_evt_exists INTO dummy;
11203 IF (c_success_evt_exists%FOUND) THEN
11204 l_success_evt_exist := 'Y';
11205 CLOSE c_success_evt_exists;
11206 ELSE
11207 l_success_evt_exist := 'N';
11208 CLOSE c_success_evt_exists;
11209 END IF;
11210
11211 IF (l_success_evt_exist = 'N') THEN
11212
11213 UPDATE gl_bc_packet_arrival_order
11214 SET affect_funds_flag = 'N'
11215 WHERE affect_funds_flag = 'Y'
11216 AND packet_id IN ( SELECT packet_id
11217 FROM gl_bc_packets bc
11218 WHERE event_id IN ( SELECT event_id
11219 FROM psa_bc_xla_events_gt
11220 )
11221 AND application_id = PSA_BC_XLA_PVT.g_application_id
11222 AND result_code IN ('F81', 'F82')
11223 ) ;
11224
11225 -- ====== FND LOG ======
11226 psa_utils.debug_other_string(g_state_level, l_full_path, ' BCTRL -> Updated GL_BC_PACKET_ARRIVAL_ORDER '||sql%rowcount||
11227 ' rows.');
11228 -- ====== FND LOG ======
11229
11230
11231 END IF;
11232
11233
11234 EXCEPTION
11235 WHEN OTHERS THEN
11236 -- ====== FND LOG ======
11237 psa_utils.debug_other_string(g_excep_level, l_full_path, ' BCTRL -> Exception Raised: '||sqlerrm);
11238 -- ====== FND LOG ======
11239 IF (c_success_evt_exists%ISOPEN) THEN
11240 CLOSE c_success_evt_exists;
11241 END IF;
11242 APP_EXCEPTION.RAISE_EXCEPTION;
11243
11244 END sync_xla_errors;
11245 BEGIN
11246 init;
11247 END PSA_FUNDS_CHECKER_PKG;
11248