[Home] [Help]
PACKAGE BODY: APPS.PSA_FUNDS_CHECKER_PKG
Source
1 PACKAGE BODY PSA_FUNDS_CHECKER_PKG AS
2 /* $Header: psafbcfb.pls 120.99.12010000.6 2008/12/19 07:55:17 sthota 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 /* ------------------------------------------------------------------------- */
241 /* */
242 /* Funds Check API for any process that needs to perform Funds Check and/or */
243 /* Funds Reservation */
244 /* */
245 /* This routine returns TRUE if successful; otherwise, it returns FALSE */
246 /* */
247 /* In case of failure, this routine will populate the global Message Stack */
248 /* using FND_MESSAGE. The calling routine will retrieve the message from */
249 /* the Stack */
250 /* */
251 /* When invoked from a Concurrent Process, the calling process has to */
252 /* initialize values for User ID, User Responsibility ID, Calling */
253 /* Application ID and Login ID. These values should be initialized, in the */
254 /* Global Stack by invoking FND_GLOBAL, prior to calling Funds Checker */
255 /* */
256 /* External Packages which are being invoked include : */
257 /* */
258 /* FND_GLOBAL */
259 /* FND_PROFILE */
260 /* FND_INSTALLATION */
261 /* FND_MESSAGE */
262 /* FND_FLEX_EXT */
263 /* FND_FLEX_APIS */
264 /* */
265 /* GL Tables which are being used include : */
266 /* */
267 /* GL_BC_PACKETS */
268 /* GL_BC_PACKET_ARRIVAL_ORDER */
269 /* GL_BC_OPTIONS */
270 /* GL_BC_OPTION_DETAILS */
271 /* GL_BC_PERIOD_MAP */
272 /* GL_BC_DUAL */
273 /* GL_BC_DUAL2 */
274 /* GL_CONCURRENCY_CONTROL */
275 /* GL_PERIOD_STATUSES */
276 /* GL_LOOKUPS */
277 /* GL_USSGL_TRANSACTION_CODES */
278 /* GL_USSGL_ACCOUNT_PAIRS */
279 /* GL_BALANCES */
280 /* GL_BUDGETS */
281 /* GL_BUDGET_VERSIONS */
282 /* GL_BUDGET_ASSIGNMENTS */
283 /* GL_BUDGET_PERIOD_RANGES */
284 /* GL_JE_BATCHES */
285 /* GL_JE_HEADERS */
286 /* GL_JE_LINES */
287 /* GL_SETS_OF_BOOKS */
288 /* GL_CODE_COMBINATIONS */
289 /* GL_ACCOUNT_HIERARCHIES */
290 /* */
291 /* AOL Tables which are being used include : */
292 /* */
293 /* FND_USER */
294 /* FND_APPLICATION */
295 /* FND_RESPONSIBILITY */
296 /* FND_PROFILE_OPTION_VALUES */
297 /* FND_PRODUCT_INSTALLATIONS */
298 /* */
299 /* ------------------------------------------------------------------------- */
300
301 -- Parameters :
302
303 -- p_ledgerid : Set of Books ID
304
305 -- p_packetid : Packet ID
306
307 -- p_mode : Funds Checker Operation Mode. Defaults to 'C' (Checking)
308
309 -- p_override : Whether to Override in case of Funds Reservation failure
310 -- because of lack of Funds. Defaults to 'N' (No)
311
312 -- p_conc_flag : Whether invoked from a Concurrent Process. Defaults to
313 -- 'N' (No)
314
315 -- p_user_id : User ID for Override (from AP AutoApproval)
316
317 -- p_user_resp_id : User Responsibility ID for Override (from AP AutoApproval)
318
319 -- p_return_code : Return Status for the Packet
320
321 --
322 -- Overloaded Version of glxfck()
323 -- This contains an additional OUT parameter p_unrsv_packet_id.
324 -- This is to be used by General Ledger only.
325 --
326
327 FUNCTION glxfck(p_ledgerid IN NUMBER,
328 p_packetid IN NUMBER,
329 p_mode IN VARCHAR2 DEFAULT 'C',
330 p_override IN VARCHAR2 DEFAULT 'N',
331 p_conc_flag IN VARCHAR2 DEFAULT 'N',
332 p_user_id IN NUMBER DEFAULT NULL,
333 p_user_resp_id IN NUMBER DEFAULT NULL,
334 p_calling_prog_flag IN VARCHAR2 DEFAULT 'G',
335 p_return_code OUT NOCOPY VARCHAR2,
336 p_unrsv_packet_id OUT NOCOPY NUMBER) RETURN BOOLEAN IS
337
338 others EXCEPTION;
339
340 -- ========================= FND LOG ===========================
341 l_full_path VARCHAR2(100);
342 -- ========================= FND LOG ===========================
343 BEGIN
344
345 l_full_path := g_path || 'glxfck - public1';
346
347 -- ========================= FND LOG ===========================
348 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_ledgerid -> ' || p_ledgerid);
349 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_packetid -> ' || p_packetid);
350 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_mode -> ' || p_mode);
351 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_override -> ' || p_override);
352 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_conc_flag -> ' || p_conc_flag);
353 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_user_id -> ' || p_user_id);
354 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_calling_prog_flag -> ' || p_calling_prog_flag);
355 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_user_resp_id -> ' || p_user_resp_id);
356 -- ========================= FND LOG ===========================
357
358 IF NOT glxfck( p_ledgerid ,
359 p_packetid ,
360 p_mode ,
361 p_override ,
362 p_conc_flag ,
363 p_user_id ,
364 p_user_resp_id ,
365 p_calling_prog_flag ,
366 p_return_code ) THEN
367
368 -- ========================= FND LOG ===========================
369 psa_utils.debug_other_string(g_state_level,l_full_path, ' glxfck --> FALSE goto gl_error');
370 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_return_code --> ' || p_return_code);
371 -- ========================= FND LOG ===========================
372 goto gl_error;
373
374 END IF;
375
376 IF (p_return_code = 'O') THEN
377 -- ========================= FND LOG ===========================
378 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_return_code --> O goto normal_exit');
379 -- ========================= FND LOG ===========================
380
381 goto normal_exit;
382 END IF;
383
384 -- Set p_unrsv_packet_id if mode is UNRESERVATION
385 -- and g_requery_flag is not set.
386
387 IF (p_mode = 'U' AND NOT g_requery_flag) THEN
388 p_unrsv_packet_id := p_packetid;
389 -- ========================= FND LOG ===========================
390 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_unrsv_packet_id --> ' || p_unrsv_packet_id );
391 -- ========================= FND LOG ===========================
392 END IF;
393
394 -- If g_requery_flag is TRUE set p_return_code = "Q"
395 -- for calling form (MJE) to requery instead of the
396 -- regular commit. [p_return code "Q" => Success/Advisory]
397
398 IF g_requery_flag THEN
399 p_return_code := 'Q';
400 -- ========================= FND LOG ===========================
401 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_return_code --> Q => Success/Advisory ');
402 -- ========================= FND LOG ===========================
403 END IF;
404
405 <<NORMAL_EXIT>>
406
407 -- ========================= FND LOG ===========================
408 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN --> TRUE ');
409 -- ========================= FND LOG ===========================
410
411 RETURN(TRUE);
412
413 <<GL_ERROR>>
414
415 -- ========================= FND LOG ===========================
416 psa_utils.debug_other_string(g_state_level,l_full_path, ' reached gl_error label ');
417 -- ========================= FND LOG ===========================
418
419 if not glxfuf then
420 -- ========================= FND LOG ===========================
421 psa_utils.debug_other_string(g_state_level,l_full_path, ' Raise OTHERS ');
422 -- ========================= FND LOG ===========================
423 raise others;
424 end if;
425
426 -- ========================= FND LOG ===========================
427 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN --> FALSE ');
428 -- ========================= FND LOG ===========================
429
430 RETURN(FALSE);
431
432 EXCEPTION
433
434 WHEN OTHERS THEN
435 -- ========================= FND LOG ===========================
436 psa_utils.debug_other_string(g_excep_level,l_full_path, ' EXCEPTION WHEN OTHERS ' || SQLERRM);
437 -- ========================= FND LOG ===========================
438
439 message_token('PROCEDURE', 'Funds Checker');
440 message_token('EVENT', SQLERRM);
441 add_message('SQLGL', 'GL_UNHANDLED_EXCEPTION');
442
443 -- ========================= FND LOG ===========================
444 psa_utils.debug_other_string(g_excep_level,l_full_path, ' RETURN --> FALSE ');
445 -- ========================= FND LOG ===========================
446
447 return(FALSE);
448
449 END glxfck;
450
451 /* =========================== GLXFCK PRIVATE ================================= */
452
453 FUNCTION glxfck(p_ledgerid IN NUMBER,
454 p_packetid IN NUMBER,
455 p_mode IN VARCHAR2 DEFAULT 'C',
456 p_override IN VARCHAR2 DEFAULT 'N',
457 p_conc_flag IN VARCHAR2 DEFAULT 'N',
458 p_user_id IN NUMBER DEFAULT NULL,
459 p_user_resp_id IN NUMBER DEFAULT NULL,
460 p_calling_prog_flag IN VARCHAR2 DEFAULT 'S',
461 p_return_code OUT NOCOPY VARCHAR2) RETURN BOOLEAN IS
462
463 cursor det_override_reqd IS
464 select 'x'
465 from gl_bc_packets bp
466 where bp.packet_id = g_packet_id
467 and bp.result_code between 'F00' and 'F19'
468 and bp.ussgl_link_to_parent_id is null
469 and bp.template_id is null
470 and nvl(bp.override_amount, -1) >=
471 abs(nvl(bp.accounted_dr, 0) - nvl(bp.accounted_cr, 0))
472 and not exists
473 (
474 select 'If Partial Resv disallowed then all non-generated ' ||
475 'detail lines that failed with any validation errors ' ||
476 'or because of Funds Availability'
477 from gl_bc_packets pk
478 where pk.packet_id = g_packet_id
479 and pk.template_id is null
480 and pk.result_code like 'F%'
481 and ((g_partial_resv_flag = 'N'
482 and pk.ussgl_link_to_parent_id is null
483 and (pk.result_code between 'F20' and 'F29'
484 or nvl(pk.override_amount, -1) <
485 abs(nvl(pk.accounted_dr, 0) - nvl(pk.accounted_cr, 0))))
486 or (pk.ussgl_link_to_parent_id = bp.ussgl_parent_id
487 and pk.result_code between 'F20' and 'F29'))
488 );
489
490 cursor ussgl_override_reqd is
491 select 'x'
492 from gl_bc_packets bp
493 where bp.packet_id = g_packet_id
494 and bp.result_code between 'F00' and 'F19'
495 and bp.ussgl_link_to_parent_id is not null
496 and exists
497 (
498 select 'Corresp Original Transaction which was Overridden'
499 from gl_bc_packets pk
500 where pk.packet_id = g_packet_id
501 and pk.ussgl_parent_id = bp.ussgl_link_to_parent_id
502 and pk.result_code = 'P21'
503 );
504
505 l_override_reqd VARCHAR2(1);
506 others EXCEPTION;
507
508 -- ========================= FND LOG ===========================
509 l_full_path VARCHAR2(100);
510 -- ========================= FND LOG ===========================
511
512 BEGIN
513
514 l_full_path := g_path || 'glxfck - private';
515
516 -- =========================== FND LOG ===========================
517 psa_utils.debug_other_string(g_state_level,l_full_path, ' GLXFCK PRIVATE - START' );
518 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_ledgerid -> ' || p_ledgerid);
519 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_packetid -> ' || p_packetid);
520 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_mode -> ' || p_mode);
521 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_override -> ' || p_override);
522 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_conc_flag -> ' || p_conc_flag);
523 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_user_id -> ' || p_user_id);
524 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_user_resp_id -> ' || p_user_resp_id);
525 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_calling_prog_flag -> ' || p_calling_prog_flag);
526 psa_utils.debug_other_string(g_state_level,l_full_path, ' Calling glxfin ');
527 -- ========================= FND LOG =============================
528
529 if (p_calling_prog_flag = 'S' and g_fcmode = 'U') then
530 -- =========================== FND LOG ===========================
531 psa_utils.debug_other_string(g_state_level,l_full_path, ' Calling Program = S and mode = Unreservation so return without processing. RETURN -> TRUE.' );
532 -- =========================== FND LOG ===========================
533 -- Since we will not be supporting unreservation functionality for SLA
534 -- return back.
535 return true;
536 end if;
537
538 -- =========================== FND LOG ===========================
539 psa_utils.debug_other_string(g_state_level,l_full_path, ' Calling glxfin - initialization ' );
540 -- =========================== FND LOG ===========================
541
542 -- Initialize Global Variables
543 if not glxfin(p_ledgerid => p_ledgerid,
544 p_packetid => p_packetid,
545 p_mode => p_mode,
546 p_override => p_override,
547 p_conc_flag => p_conc_flag,
548 p_user_id => p_user_id,
549 p_user_resp_id => p_user_resp_id,
550 p_calling_prog_flag => p_calling_prog_flag) then
551
552 -- =========================== FND LOG ===========================
553 psa_utils.debug_other_string(g_state_level,l_full_path, ' glxfin --> RETURN FALSE -> goto fatal_error');
554 -- ========================= FND LOG =============================
555
556 goto fatal_error;
557 end if;
558
559 -- =========================== FND LOG ===========================
560 psa_utils.debug_other_string(g_state_level,l_full_path, ' Calling glxfcp - preprocessor ');
561 -- ========================= FND LOG =============================
562
563 -- Funds Check Processor
564 if not glxfcp then
565 -- =========================== FND LOG ===========================
566 psa_utils.debug_other_string(g_state_level,l_full_path, ' glxfcp --> RETURN FALSE -> goto fatal_error');
567 -- ========================= FND LOG =============================
568 goto fatal_error;
569 end if;
570
571
572 if g_overlapping_budget=TRUE then
573 -- =========================== FND LOG ===========================
574 psa_utils.debug_other_string(g_state_level,l_full_path, ' return_code --> F');
575 -- ========================= FND LOG =============================
576
577 p_return_code := 'F';
578
579 -- =========================== FND LOG ===========================
580 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN --> TRUE ');
581 -- ========================= FND LOG =============================
582 return(TRUE);
583
584 end if ;
585
586
587 -- Override Transactions
588 if g_override_flag and g_calling_prog_flag = 'G' and not g_conc_flag then
589
590 -- =========================== FND LOG ===========================
591 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_override_flag --> TRUE ');
592 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_calling_prog_flag --> G ');
593 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_conc_flag --> FALSE ');
594 -- ========================= FND LOG =============================
595
596 open det_override_reqd;
597 fetch det_override_reqd INTO l_override_reqd;
598
599 if (det_override_reqd%NOTFOUND) then
600
601 -- =========================== FND LOG ===========================
602 psa_utils.debug_other_string(g_state_level,l_full_path, ' det_override_reqd%NOTFOUND ');
603 -- ========================= FND LOG =============================
604
605 open ussgl_override_reqd;
606 fetch ussgl_override_reqd INTO l_override_reqd;
607
608 if (ussgl_override_reqd%FOUND) then
609
610 -- =========================== FND LOG ===========================
611 psa_utils.debug_other_string(g_state_level,l_full_path, ' ussgl_override_reqd%FOUND ');
612 -- ========================= FND LOG =============================
613
614 g_return_code := 'O';
615 goto normal_exit;
616 end if;
617
618 else
619
620 -- =========================== FND LOG ===========================
621 psa_utils.debug_other_string(g_state_level,l_full_path, ' det_override_reqd%FOUND ');
622 -- ========================= FND LOG =============================
623
624 g_return_code := 'O';
625 goto normal_exit;
626 end if;
627
628 end if;
629
630 -- =========================== FND LOG ===========================
631 psa_utils.debug_other_string(g_state_level,l_full_path, ' Calling glxcon ');
632 -- ========================= FND LOG =============================
633
634 -- Set Result Codes, Return Code, Append Journal Logic
635 if not glxcon then
636 -- =========================== FND LOG ===========================
637 psa_utils.debug_other_string(g_state_level,l_full_path, ' glxcon --> RETURN FALSE -> goto fatal_error');
638 -- ========================= FND LOG =============================
639 goto fatal_error;
640 end if;
641
642 -- =========================== FND LOG ===========================
643 psa_utils.debug_other_string(g_state_level,l_full_path, ' Calling glrchk ');
644 -- ========================= FND LOG =============================
645
646 if not glrchk('X') then
647 -- =========================== FND LOG ===========================
648 psa_utils.debug_other_string(g_state_level,l_full_path, ' glrchk --> RETURN FALSE -> goto fatal_error');
649 -- ========================= FND LOG =============================
650 goto fatal_error;
651 end if;
652
653 <<NORMAL_EXIT>>
654
655 IF (det_override_reqd%ISOPEN) THEN
656 close det_override_reqd;
657 END IF;
658
659 IF (ussgl_override_reqd%ISOPEN) THEN
660 close ussgl_override_reqd;
661 END IF;
662
663 -- =========================== FND LOG ===========================
664 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_return_code --> ' || g_return_code);
665 -- ========================= FND LOG =============================
666
667 p_return_code := g_return_code;
668
669 -- =========================== FND LOG ===========================
670 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN --> TRUE ');
671 -- ========================= FND LOG =============================
672
673 return(TRUE);
674
675
676 <<fatal_error>>
677
678 -- =========================== FND LOG ===========================
679 psa_utils.debug_other_string(g_state_level,l_full_path, ' Reached FATAL ERROR LABEL ');
680 -- ========================= FND LOG =============================
681
682 if not glxfuf then
683 -- =========================== FND LOG ===========================
684 psa_utils.debug_other_string(g_state_level,l_full_path, ' glxfuf --> RETURN FALSE -> RAISE OTHERS');
685 -- ========================= FND LOG =============================
686 raise others;
687 end if;
688
689 -- =========================== FND LOG ===========================
690 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN -> FALSE ');
691 -- ========================= FND LOG =============================
692
693 return(FALSE);
694
695 EXCEPTION
696
697 WHEN OTHERS THEN
698 -- =========================== FND LOG ===========================
699 psa_utils.debug_other_string(g_excep_level,l_full_path, ' EXCEPTION WHEN OTHERS ' || SQLERRM);
700 psa_utils.debug_other_string(g_excep_level,l_full_path, ' RETURN -> FALSE ');
701 -- ========================= FND LOG =============================
702
703 message_token('PROCEDURE', 'Funds Checker');
704 message_token('EVENT', SQLERRM);
705 add_message('SQLGL', 'GL_UNHANDLED_EXCEPTION');
706
707 return(FALSE);
708
709 END glxfck;
710
711 /* ================================ GLXFIN ================================ */
712
713 -- Initialize Global Variables
714
715 FUNCTION glxfin(p_ledgerid IN NUMBER,
716 p_packetid IN NUMBER,
717 p_mode IN VARCHAR2,
718 p_override IN VARCHAR2,
719 p_conc_flag IN VARCHAR2,
720 p_user_id IN NUMBER,
721 p_user_resp_id IN NUMBER,
722 p_calling_prog_flag IN VARCHAR2) RETURN BOOLEAN IS
723
724 i BINARY_INTEGER;
725 l_status fnd_product_installations.status%TYPE;
726 l_industry fnd_profile_option_values.profile_option_value%TYPE;
727 l_value fnd_profile_option_values.profile_option_value%TYPE;
728 l_reverse_tc_flag fnd_profile_option_values.profile_option_value%TYPE;
729 l_fv_prepay_prof fnd_profile_option_values.profile_option_value%TYPE;
730 l_fv_prepay_defined BOOLEAN;
731 l_defined BOOLEAN;
732 l_reverse_tc_defined BOOLEAN;
733
734 l_pa_status VARCHAR2(1);
735 l_pa_enabled INTEGER;
736
737 l_gms_status VARCHAR2(1);
738 l_gms_enabled INTEGER;
739
740 l_efc_status VARCHAR2(1);
741 l_efc_enabled VARCHAR2(1);
742 l_cbc_enabled VARCHAR2(1);
743
744 l_igi_status VARCHAR2(1);
745
746 l_prepare_stmt VARCHAR2(2000);
747
748 CURSOR set_of_books is
749 SELECT chart_of_accounts_id,
750 currency_code
751 FROM gl_ledgers_public_v
752 WHERE ledger_id = g_ledger_id;
753
754 others EXCEPTION;
755
756 -- ========================= FND LOG ===========================
757 l_full_path VARCHAR2(100);
758 -- ========================= FND LOG ===========================
759 BEGIN
760
761 l_full_path := g_path || 'glxfin';
762
763 -- =========================== FND LOG ===========================
764 psa_utils.debug_other_string(g_state_level,l_full_path, ' GLXFIN - START' );
765 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_ledgerid -> ' || p_ledgerid);
766 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_packetid -> ' || p_packetid);
767 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_mode -> ' || p_mode);
768 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_override -> ' || p_override);
769 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_conc_flag -> ' || p_conc_flag);
770 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_user_id -> ' || p_user_id);
771 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_user_resp_id -> ' || p_user_resp_id);
772 -- ========================= FND LOG =============================
773
774 g_psa_pacheck := FALSE;
775 g_psa_grantcheck := FALSE;
776 g_cbc_enabled := FALSE;
777 g_summarized_flag := FALSE;
778 g_append_je_flag := FALSE;
779 g_requery_flag := FALSE;
780 g_ussgl_option_flag := FALSE;
781 g_overlapping_budget := FALSE; -- Used When there are multiple overlapping budgets for the account
782
783
784 -- =========================== FND LOG ===========================
785 psa_utils.debug_other_string(g_state_level,l_full_path, ' SETTING VARIABLES ' );
786 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_psa_pacheck -> FALSE');
787 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_psa_grantcheck -> FALSE');
788 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_cbc_enabled -> FALSE');
789 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_summarized_flag -> FALSE');
790 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_append_je_flag -> FALSE');
791 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_requery_flag -> FALSE');
792 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_ussgl_option_flag -> FALSE');
793 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_overlapping_budget -> FALSE');
794 -- ========================= FND LOG =============================
795
796 /*===========================================+
797 | Assign Parameters to Global Variables |
798 +===========================================*/
799
800 g_ledger_id := p_ledgerid;
801 g_packet_id := p_packetid;
802 g_fcmode := p_mode;
803
804 -- ========================= FND LOG =============================
805 psa_utils.debug_other_string(g_state_level,l_full_path, 'Calling Get_Session_Details to fetch session variables');
806 -- ========================= FND LOG =============================
807
808 Get_Session_Details(g_session_id, g_serial_id);
809
810 -- ========================= FND LOG =============================
811 psa_utils.debug_other_string(g_state_level,l_full_path, 'Session_Id = '||g_session_id);
812 psa_utils.debug_other_string(g_state_level,l_full_path, 'Serial_Id = '||g_serial_id);
813 -- ========================= FND LOG =============================
814
815 IF p_calling_prog_flag IN ('P', 'H') THEN
816 -- ========================= FND LOG =============================
817 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_calling_prog_flag = P or H -> g_calling_prog_flag = S');
818 -- ========================= FND LOG =============================
819
820 g_calling_prog_flag := 'S';
821 ELSE
822 -- ========================= FND LOG =============================
823 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);
824 -- ========================= FND LOG =============================
825
826 g_calling_prog_flag := p_calling_prog_flag;
827 END IF;
828
829 IF g_fcmode ='C' THEN -- Funds Check Partial Mode Check
830 -- ========================= FND LOG =====================================
831 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_fcmode = C -> g_partial_resv_flag = Y');
832 -- ========================= FND LOG =====================================
833
834 g_partial_resv_flag := 'Y';
835 ELSIF g_fcmode = 'M' THEN -- Funds Check Full Mode Check
836 -- ========================= FND LOG =====================================
837 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_fcmode = M -> g_partial_resv_flag = N');
838 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_fcmode = M -> g_fcmode = C');
839 -- ========================= FND LOG =====================================
840
841 g_partial_resv_flag := 'N';
842 g_fcmode := 'C';
843 ELSIF g_fcmode = 'P' THEN -- Funds Reserve Partial Mode Check
844 -- ========================= FND LOG =====================================
845 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_fcmode = P -> g_partial_resv_flag = Y');
846 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_fcmode = P -> g_fcmode = R');
847 -- ========================= FND LOG =====================================
848
849 g_partial_resv_flag := 'Y';
850 g_fcmode := 'R';
851 ELSE
852 -- ========================= FND LOG =====================================
853 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_fcmode != C, M and P -> g_partial_resv_flag = N');
854 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_fcmode -> '||g_fcmode);
855 -- ========================= FND LOG =====================================
856
857 g_partial_resv_flag := 'N';
858 END IF;
859
860 -- =========================== FND LOG ===========================
861 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_ledger_id -> ' || g_ledger_id);
862 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_packet_id -> ' || g_packet_id);
863 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_fcmode -> ' || g_fcmode);
864 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_partial_resv_flag -> '|| g_partial_resv_flag);
865 -- ========================= FND LOG =============================
866
867 /*========================+
868 | Set Overrides Flag |
869 +========================*/
870
871 if (p_override = 'N') then
872 -- =========================== FND LOG ===========================
873 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_override = N -> g_override_flag = FALSE');
874 -- =========================== FND LOG ===========================
875
876 g_override_flag := FALSE;
877 else
878 -- =========================== FND LOG ===========================
879 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_override != N -> g_override_flag = TRUE');
880 -- =========================== FND LOG ===========================
881
882 g_override_flag := TRUE;
883 end if;
884
885 /*========================+
886 | Get AOL User ID |
887 +========================*/
888
889 if ((g_override_flag) and
890 (p_user_id is not null)) then
891 g_user_id := p_user_id;
892 else
893 g_user_id := FND_GLOBAL.USER_ID;
894 end if;
895
896 -- =========================== FND LOG ===========================
897 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_user_id -> ' || g_user_id);
898 -- ========================= FND LOG =============================
899
900 if g_user_id = -1 then
901 message_token('PROCEDURE', 'Funds Checker');
902 add_message('SQLGL', 'GL_INVALID_USERID');
903 -- =========================== FND LOG ===========================
904 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN -> FALSE');
905 -- ========================= FND LOG =============================
906 g_debug := g_debug||' GLXFIN Failed : G_USER_ID = -1';
907 return(FALSE);
908 end if;
909
910 /*==============================+
911 | Get Calling Application ID |
912 +==============================*/
913
914 g_resp_appl_id := FND_GLOBAL.resp_appl_id;
915
916 if g_resp_appl_id = -1 then
917 g_resp_appl_id := 101;
918 end if;
919
920 -- =========================== FND LOG ===========================
921 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_resp_appl_id -> ' || g_resp_appl_id);
922 -- ========================= FND LOG =============================
923
924 /*=========================+
925 | Get Responsibility ID |
926 +=========================*/
927
928 if ((g_override_flag) and
929 (p_user_resp_id is not null)) then
930 g_user_resp_id := p_user_resp_id;
931 else
932 g_user_resp_id := FND_GLOBAL.RESP_ID;
933 end if;
934
935 -- =========================== FND LOG ===========================
936 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_user_resp_id -> ' || g_user_resp_id);
937 -- ========================= FND LOG =============================
938
939 if g_user_resp_id = -1 then
940 message_token('PROCEDURE', 'Funds Checker');
941 add_message('SQLGL', 'GL_INVALID_RESPID');
942 -- =========================== FND LOG ===========================
943 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN -> FALSE');
944 -- ========================= FND LOG =============================
945 g_debug := g_debug||' GLXFIN Failed : G_USER_RESP_ID = -1';
946 return(FALSE);
947 end if;
948
949 /*========================================+
950 | Whether invoked from a Batch Process |
951 +========================================*/
952
953
954 if (p_conc_flag = 'N') then
955 g_conc_flag := FALSE;
956 else
957 g_conc_flag := TRUE;
958 end if;
959
960 -- =========================== FND LOG ===========================
961 IF (g_conc_flag) THEN
962 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_conc_flag -> TRUE');
963 ELSE
964 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_conc_flag -> FALSE');
965 END IF;
966 -- ========================= FND LOG =============================
967
968 IF g_calling_prog_flag = 'G' THEN
969
970 -- Get GL Installation Info
971 -- The installation info is now implemented as a profile option (INDUSTRY).
972
973 FND_PROFILE.GET_SPECIFIC('INDUSTRY',
974 g_user_id,
975 g_user_resp_id,
976 g_resp_appl_id,
977 l_industry,
978 l_defined);
979
980 -- =========================== FND LOG ===========================
981 psa_utils.debug_other_string(g_state_level,l_full_path, ' Getting INDUSTRY details ');
982 -- ========================= FND LOG =============================
983
984 if not l_defined then
985 if not FND_INSTALLATION.GET(g_resp_appl_id,
986 101,
987 l_status,
988 l_industry) then
989
990 message_token('ROUTINE', 'Funds Checker');
991 add_message('SQLGL', 'GL_CANT_GET_INSTALL_INDUSTRY');
992 -- =========================== FND LOG ===========================
993 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN -> FALSE');
994 -- ========================= FND LOG =============================
995 g_debug := g_debug||' GLXFIN Failed : Oracle General Ledger
996 was unable to get installation industry from Funds Checker.
997 Contact your system administrator.';
998 return(FALSE);
999 end if;
1000 end if;
1001
1002
1003 -- Check for Profiles if Government Install
1004
1005 -- =========================== FND LOG ===========================
1006 psa_utils.debug_other_string(g_state_level,l_full_path, ' l_industry -> ' || l_industry);
1007 -- ========================= FND LOG =============================
1008
1009 if l_industry = 'G' then
1010
1011 FND_PROFILE.GET('USSGL_OPTION', l_value);
1012
1013 if l_value is null then
1014 -- =========================== FND LOG ===========================
1015 psa_utils.debug_other_string(g_state_level,l_full_path, ' RAISE OTHERS');
1016 -- ========================= FND LOG =============================
1017 raise others;
1018 end if;
1019
1020 -- =========================== FND LOG ===========================
1021 psa_utils.debug_other_string(g_state_level,l_full_path, ' USSGL_OPTION, l_value -> ' || l_Value);
1022 -- ========================= FND LOG =============================
1023
1024 if l_value = 'Y' then
1025 -- =========================== FND LOG ===========================
1026 psa_utils.debug_other_string(g_state_level,l_full_path, ' G_USSGL_OPTION_FLAG -> TRUE ');
1027 -- ========================= FND LOG =============================
1028 g_ussgl_option_flag := TRUE;
1029 end if;
1030
1031 if g_ussgl_option_flag then
1032
1033 FND_PROFILE.GET_SPECIFIC('FV_SPLIT_INV_DISTRIBUTION_PREPAY',
1034 g_user_id,
1035 g_user_resp_id,
1036 g_resp_appl_id,
1037 l_fv_prepay_prof,
1038 l_fv_prepay_defined);
1039
1040 -- =========================== FND LOG ===========================
1041 psa_utils.debug_other_string(g_state_level,l_full_path, ' l_fv_prepay_prof -> ' || l_fv_prepay_prof);
1042 -- ========================= FND LOG =============================
1043
1044 if l_fv_prepay_prof = 'Y' then
1045 g_fv_prepay_prof := TRUE;
1046 else
1047 g_fv_prepay_prof := FALSE;
1048 end if;
1049
1050 -- =========================== FND LOG ===========================
1051 IF (g_fv_prepay_prof) THEN
1052 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_fv_prepay_prof -> TRUE');
1053 ELSE
1054 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_fv_prepay_prof -> FALSE');
1055 END IF;
1056 -- ========================= FND LOG =============================
1057
1058 end if;
1059
1060 -- Bug 678604
1061 FND_PROFILE.GET_SPECIFIC('GL_REVERSE_TC_OPTION',
1062 g_user_id,
1063 g_user_resp_id,
1064 g_resp_appl_id,
1065 l_reverse_tc_flag,
1066 l_reverse_tc_defined);
1067
1068 if not l_reverse_tc_defined then
1069 g_reverse_tc_flag := 'Y';
1070 else
1071 g_reverse_tc_flag := l_reverse_tc_flag;
1072 end if;
1073
1074 -- =========================== FND LOG ===========================
1075 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_reverse_tc_flag -> ' || g_reverse_tc_flag);
1076 -- ========================= FND LOG =============================
1077
1078 end if; -- l_industry = 'G'
1079
1080 end if; -- g_calling_prog_flag = 'G'
1081
1082
1083 /*
1084 FND_PROFILE.GET('CREATE_BUDGETARY_ENCUMBRANCES', l_value);
1085
1086 -- =========================== FND LOG ===========================
1087 psa_utils.debug_other_string(g_state_level,l_full_path, ' CBE - l_value -> ' || l_Value);
1088 -- ========================= FND LOG =============================
1089
1090 if l_value is null then
1091 -- =========================== FND LOG ===========================
1092 psa_utils.debug_other_string(g_state_level,l_full_path, ' l_value is null -> raise others');
1093 -- ========================= FND LOG =============================
1094
1095 raise others;
1096 else
1097 -- =========================== FND LOG ===========================
1098 psa_utils.debug_other_string(g_state_level,l_full_path, ' l_value not null -> g_budgetary_enc_flag = l_value = ' || l_value);
1099 -- ========================= FND LOG =============================
1100
1101 g_budgetary_enc_flag := l_value;
1102 end if;
1103
1104 */
1105
1106
1107 -- Get PSA Debug Mode profile value
1108
1109 FND_PROFILE.GET('PSA_DEBUG_MODE', l_value);
1110
1111 IF l_value = 'Y' THEN
1112 -- =========================== FND LOG ===========================
1113 psa_utils.debug_other_string(g_state_level,l_full_path, ' l_value = Y -> g_xla_debug = TRUE');
1114 -- ========================= FND LOG =============================
1115
1116 g_xla_debug := TRUE;
1117 ELSE
1118 -- =========================== FND LOG ===========================
1119 psa_utils.debug_other_string(g_state_level,l_full_path, ' l_value != Y -> g_xla_debug = FALSE');
1120 -- ========================= FND LOG =============================
1121
1122 g_xla_debug := FALSE;
1123 END IF;
1124
1125
1126 -- Get Budgetary Control Option
1127
1128 if ((g_override_flag) and
1129 (p_user_id is not null) and
1130 (p_user_resp_id is not null)) then
1131
1132 FND_PROFILE.GET_SPECIFIC('BUDGETARY_CONTROL_OPTION',
1133 p_user_id,
1134 p_user_resp_id,
1135 g_resp_appl_id,
1136 l_value,
1137 l_defined);
1138 else
1139 FND_PROFILE.GET('BUDGETARY_CONTROL_OPTION', l_value);
1140 end if;
1141
1142 g_bc_option_id := to_number(l_value);
1143
1144 -- =========================== FND LOG ===========================
1145 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_bc_option_id -> ' || g_bc_option_id);
1146 -- ========================= FND LOG =============================
1147
1148 g_return_code := NULL;
1149
1150 g_num_segs := 0;
1151
1152 -- =========================== FND LOG ===========================
1153 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_return_code -> ' || g_return_code);
1154 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_num_segs -> ' || g_num_segs);
1155 -- ========================= FND LOG =============================
1156
1157 for i in 1..30 loop
1158 seg_name(i) := null;
1159 seg_val(i) := null;
1160 end loop;
1161
1162
1163 /*============================+
1164 | Check for PA enabled |
1165 +=============================*/
1166
1167 -- =========================== FND LOG ===========================
1168 psa_utils.debug_other_string(g_state_level,l_full_path, ' Check PA is enable or not ' );
1169 -- ========================= FND LOG =============================
1170
1171 BEGIN
1172 l_industry := NULL;
1173 l_prepare_stmt := NULL;
1174 l_pa_status := 'N';
1175
1176 IF FND_INSTALLATION.GET(275, 275, l_pa_status, l_industry) THEN
1177
1178 IF l_pa_status ='I' THEN
1179
1180 l_pa_enabled := 0;
1181 l_prepare_stmt := 'BEGIN IF PA_BUDGET_FUND_PKG.IS_PA_BC_ENABLED() THEN'||' :1 := 1; END IF; END;';
1182
1183 -- =========================== FND LOG ===========================
1184 psa_utils.debug_other_string(g_state_level,l_full_path, ' l_prepare_stmt -> ' || l_prepare_stmt );
1185 -- ========================= FND LOG =============================
1186
1187 EXECUTE IMMEDIATE l_prepare_stmt USING OUT l_pa_enabled;
1188
1189 -- =========================== FND LOG ===========================
1190 psa_utils.debug_other_string(g_state_level,l_full_path, ' l_pa_enabled -> ' || l_pa_enabled );
1191 -- ========================= FND LOG =============================
1192
1193
1194 IF l_pa_enabled = 1 THEN
1195
1196 g_psa_pacheck := TRUE;
1197
1198 -- =========================== FND LOG ===========================
1199 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_psa_pacheck --> TRUE ' );
1200 -- ========================= FND LOG =============================
1201
1202 END IF;
1203 END IF;
1204 END IF;
1205
1206 EXCEPTION
1207 WHEN OTHERS THEN
1208 g_psa_pacheck := FALSE;
1209
1210 -- =========================== FND LOG ===========================
1211 psa_utils.debug_other_string(g_excep_level,l_full_path, ' g_psa_pacheck --> FALSE ' );
1212 psa_utils.debug_other_string(g_excep_level,l_full_path, ' ERROR: '||sqlerrm );
1213 -- ========================= FND LOG =============================
1214 END;
1215
1216
1217 /*============================+
1218 | Check for GMS enabled |
1219 +=============================*/
1220
1221 -- =========================== FND LOG ===========================
1222 psa_utils.debug_other_string(g_state_level,l_full_path, ' Check GMS is enable or not ' );
1223 -- ========================= FND LOG =============================
1224 BEGIN
1225 l_industry := NULL;
1226 l_prepare_stmt := NULL;
1227 l_gms_status := 'N';
1228
1229 IF FND_INSTALLATION.GET(8402, 8402, l_gms_status, l_industry) THEN
1230
1231 IF l_gms_status ='I' THEN
1232
1233 l_gms_enabled := 0;
1234 l_prepare_stmt := 'BEGIN IF GMS_INSTALL.ENABLED() THEN'||' :1 := 1; END IF; END;';
1235
1236 -- =========================== FND LOG ===========================
1237 psa_utils.debug_other_string(g_state_level,l_full_path, ' l_prepare_stmt -> ' || l_prepare_stmt );
1238 -- ========================= FND LOG =============================
1239
1240 EXECUTE IMMEDIATE l_prepare_stmt USING OUT l_gms_enabled;
1241
1242 -- =========================== FND LOG ===========================
1243 psa_utils.debug_other_string(g_state_level,l_full_path, ' l_gms_enabled -> ' || l_gms_enabled );
1244 -- ========================= FND LOG =============================
1245
1246
1247 IF l_gms_enabled = 1 THEN
1248
1249 g_psa_grantcheck := TRUE;
1250
1251 -- =========================== FND LOG ===========================
1252 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_psa_grantcheck --> TRUE ' );
1253 -- ========================= FND LOG =============================
1254
1255 END IF;
1256 END IF;
1257 END IF;
1258
1259 EXCEPTION
1260 WHEN OTHERS THEN
1261 g_psa_grantcheck := FALSE;
1262
1263 -- =========================== FND LOG ===========================
1264 psa_utils.debug_other_string(g_excep_level,l_full_path, ' g_psa_grantcheck --> FALSE ' );
1265 psa_utils.debug_other_string(g_excep_level,l_full_path, ' ERROR: '||sqlerrm );
1266 -- ========================= FND LOG =============================
1267 END;
1268
1269
1270 /*========================+
1271 | Check CBC Enabled |
1272 +========================*/
1273
1274 -- =========================== FND LOG ===========================
1275 psa_utils.debug_other_string(g_state_level,l_full_path, ' Check CBC is enabled or not' );
1276 -- ========================= FND LOG =============================
1277
1278 BEGIN
1279
1280 IF (l_igi_status = 'I') THEN
1281
1282 l_prepare_stmt := 'SELECT cc_bc_enable_flag FROM igc_cc_bc_enable WHERE set_of_books_id = :1';
1283 -- =========================== FND LOG ===========================
1284 psa_utils.debug_other_string(g_state_level,l_full_path, ' l_prepare_stmt -> ' || l_prepare_stmt );
1285 -- ========================= FND LOG =============================
1286
1287 EXECUTE IMMEDIATE l_prepare_stmt INTO l_cbc_enabled USING g_ledger_id;
1288
1289 IF (l_cbc_enabled = 'Y') THEN
1290 g_cbc_enabled := TRUE;
1291 END IF;
1292 END IF;
1293
1294 EXCEPTION
1295 WHEN OTHERS THEN
1296 g_cbc_enabled := FALSE;
1297 -- =========================== FND LOG ===========================
1298 psa_utils.debug_other_string(g_excep_level,l_full_path, ' g_cbc_enabled --> FALSE ' );
1299 psa_utils.debug_other_string(g_excep_level,l_full_path, ' ERROR: '||sqlerrm );
1300 -- ========================= FND LOG =============================
1301 END;
1302
1303
1304 IF g_cbc_enabled THEN
1305 -- =========================== FND LOG ===========================
1306 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_cbc_enabled --> TRUE');
1307 -- ========================= FND LOG =============================
1308 ELSE
1309 -- =========================== FND LOG ===========================
1310 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_cbc_enabled --> FALSE');
1311 -- ========================= FND LOG =============================
1312 END IF;
1313
1314
1315 /*================================================================================+
1316 | Get Chart of Accounts and Functional Currency Code for this Set of Books |
1317 +================================================================================*/
1318
1319 OPEN set_of_books;
1320 FETCH set_of_books INTO g_coa_id, g_func_curr_code;
1321 CLOSE set_of_books;
1322
1323 -- =========================== FND LOG ===========================
1324 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_coa_id -> ' || g_coa_id);
1325 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_func_curr_code -> ' || g_func_curr_code);
1326 -- ========================= FND LOG =============================
1327
1328 -- ===============================================================
1329 psa_utils.debug_other_string(g_state_level,l_full_path,'Getting value of Profile PSA_ENABLE_EFC');
1330 -- ===============================================================
1331
1332 FND_PROFILE.GET('PSA_ENABLE_EFC',g_enable_efc_flag);
1333
1334 -- ================================================================
1335 psa_utils.debug_other_string(g_state_level,l_full_path,'Value of Profile PSA_ENABLE_EFC' || g_enable_efc_flag);
1336 -- ================================================================
1337
1338 -- =========================== FND LOG ===========================
1339 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN -> TRUE');
1340 -- ========================= FND LOG =============================
1341
1342 return(TRUE);
1343
1344
1345 EXCEPTION
1346
1347 WHEN OTHERS THEN
1348 -- ========================= FND LOG ===========================
1349 psa_utils.debug_other_string(g_excep_level,l_full_path, ' EXCEPTION WHEN OTHERS ' || SQLERRM);
1350 -- ========================= FND LOG ===========================
1351
1352 message_token('PROCEDURE', 'Funds Checker');
1353 message_token('EVENT', SQLERRM);
1354 add_message('SQLGL', 'GL_UNHANDLED_EXCEPTION');
1355
1356 -- ========================= FND LOG ===========================
1357 psa_utils.debug_other_string(g_excep_level,l_full_path, ' RETURN --> FALSE ');
1358 -- ========================= FND LOG ===========================
1359 g_debug := g_debug||' GLXFIN Failed : '||SQLERRM;
1360
1361 return(FALSE);
1362
1363
1364 END glxfin;
1365
1366 /* ============================ GLXFCP =============================== */
1367
1368 -- Funds Check Processor
1369 FUNCTION glxfcp RETURN BOOLEAN IS
1370
1371 PRAGMA AUTONOMOUS_TRANSACTION;
1372
1373 CURSOR source_cat IS
1374 SELECT distinct je_source_name, je_category_name
1375 FROM gl_bc_packets
1376 WHERE packet_id = decode(g_fcmode, 'U', g_packet_id_ursvd, g_packet_id);
1377
1378 l_option_selected NUMBER;
1379
1380 -- ========================= FND LOG ===========================
1381 l_full_path VARCHAR2(100);
1382 -- ========================= FND LOG ===========================
1383 BEGIN
1384
1385 l_full_path := g_path || 'glxfcp';
1386
1387 -- =========================== FND LOG ===========================
1388 psa_utils.debug_other_string(g_state_level,l_full_path, ' GLXFCP - START' );
1389 -- ========================= FND LOG =============================
1390
1391 --
1392 -- If Mode is Unreservation, assign Packet ID to Unreservation Packet ID
1393 -- and initialize Packet ID to 0. This is done here to prevent the approved
1394 -- packet from accidentally being updated to status 'Fatal' in case a fatal
1395 -- error occurs before glxfiu()
1396 --
1397
1398 -- =========================== FND LOG ===========================
1399 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_fcmode -> ' || g_fcmode);
1400 -- ========================= FND LOG =============================
1401
1402 if g_fcmode = 'U' then
1403 g_packet_id_ursvd := g_packet_id;
1404 g_packet_id := 0;
1405 else
1406 g_packet_id_ursvd := 0;
1407 end if;
1408
1409 -- =========================== FND LOG ===========================
1410 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_packet_id_ursvd -> ' || g_packet_id_ursvd);
1411 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_packet_id -> ' || g_packet_id);
1412 -- ========================= FND LOG =============================
1413
1414 IF g_cbc_enabled THEN
1415
1416 -- =========================== FND LOG ===========================
1417 psa_utils.debug_other_string(g_state_level,l_full_path, ' Calling GLZCBC ');
1418 -- ========================= FND LOG =============================
1419
1420 g_cbc_retcode := glzcbc;
1421
1422 -- =========================== FND LOG ===========================
1423 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_cbc_retcode -> ' || g_cbc_retcode);
1424 -- ========================= FND LOG =============================
1425
1426 IF g_cbc_retcode = -1 THEN
1427
1428 -- =========================== FND LOG ===========================
1429 psa_utils.debug_other_string(g_state_level,l_full_path, ' glzcbc RETURN -> FALSE');
1430 psa_utils.debug_other_string(g_state_level,l_full_path, ' ERROR: ROLLBACK, RETURN -> FALSE');
1431 -- ========================= FND LOG =============================
1432
1433 g_debug := g_debug||' GLXFCP Failed : G_CBC_RETOCDE = -1';
1434 -- Bug 3214062
1435 rollback;
1436 RETURN FALSE;
1437
1438 ELSIF g_cbc_retcode = 0 THEN
1439
1440 -- =========================== FND LOG ===========================
1441 psa_utils.debug_other_string(g_state_level,l_full_path, ' Calling glxfrc ');
1442 -- ========================= FND LOG =============================
1443
1444 if not glxfrc then
1445 -- =========================== FND LOG ===========================
1446 psa_utils.debug_other_string(g_state_level,l_full_path, ' glxfrc RETURN -> FALSE');
1447 psa_utils.debug_other_string(g_state_level,l_full_path, ' ERROR: ROLLBACK, RETURN -> FALSE');
1448 -- ========================= FND LOG =============================
1449
1450 -- Bug 3214062
1451 rollback;
1452 RETURN FALSE;
1453 end if;
1454
1455 -- Bug 3214062
1456 commit;
1457
1458 -- =========================== FND LOG ===========================
1459 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN -> TRUE');
1460 -- ========================= FND LOG =============================
1461
1462 RETURN TRUE;
1463
1464 END IF;
1465
1466 END IF; -- g_cbc_enabled
1467
1468 -- =========================== FND LOG ===========================
1469 psa_utils.debug_other_string(g_state_level,l_full_path, ' resetting g_append_je_flag to FALSE ');
1470 -- ========================= FND LOG =============================
1471
1472 -- Reset Append JE Flag
1473 g_append_je_flag := FALSE;
1474
1475
1476 -- If USSGL Option is enabled and Mode is not Unreservation, process
1477 -- USSGL transactions
1478
1479 if ((g_ussgl_option_flag) and
1480 (g_fcmode <> 'U')) then
1481
1482 -- =========================== FND LOG ===========================
1483 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_ussgl_option_flag -> TRUE ');
1484 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_fcmode <> U ');
1485 psa_utils.debug_other_string(g_state_level,l_full_path, ' Calling fv_prepay_pkg ');
1486 -- ========================= FND LOG =============================
1487
1488 if not fv_prepay_pkg then
1489 -- =========================== FND LOG ===========================
1490 psa_utils.debug_other_string(g_state_level,l_full_path, ' fv_prepay_pkg - RETURN -> FALSE');
1491 -- ========================= FND LOG =============================
1492 g_debug := g_debug||' GLXFCP Failed : FV_PREPAY_PKG failed';
1493 rollback;
1494 return (FALSE);
1495 end if;
1496
1497 -- =========================== FND LOG ===========================
1498 psa_utils.debug_other_string(g_state_level,l_full_path, ' Calling glxfug ');
1499 -- ========================= FND LOG =============================
1500
1501 if not glxfug then
1502 -- =========================== FND LOG ===========================
1503 psa_utils.debug_other_string(g_state_level,l_full_path, ' GLXFUG - RETURN -> FALSE');
1504 -- ========================= FND LOG =============================
1505 rollback;
1506 return(FALSE);
1507 end if;
1508
1509 end if;
1510
1511 -- If Project Accounting Funds Check indicated, callout to allow
1512 -- for proper pre-processing.
1513
1514 if g_psa_pacheck then
1515 -- =========================== FND LOG ===========================
1516 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_psa_pacheck -> TRUE');
1517 -- ========================= FND LOG =============================
1518
1519 if not glzpafck then
1520 -- =========================== FND LOG ===========================
1521 psa_utils.debug_other_string(g_state_level,l_full_path, ' glzpafck - RETURN -> FALSE');
1522 -- ========================= FND LOG =============================
1523 rollback;
1524 return(FALSE);
1525 end if;
1526
1527 end if;
1528
1529 -- =========================== FND LOG ===========================
1530 psa_utils.debug_other_string(g_state_level,l_full_path, ' Populating records in PSA_OPTION_DETAILS_GT ');
1531 -- ========================= FND LOG =============================
1532
1533 FOR indx IN source_cat
1534 LOOP
1535 SELECT MIN(CASE) INTO l_option_selected
1536 FROM (
1537 SELECT CASE
1538 WHEN (bc.je_source_name = indx.je_source_name) AND (bc.je_category_name = indx.je_category_name) THEN
1539 1
1540 WHEN (bc.je_source_name = indx.je_source_name) AND (bc.je_category_name = 'Other') THEN
1541 2
1542 WHEN (bc.je_category_name = indx.je_category_name) AND (bc.je_source_name = 'Other') THEN
1543 3
1544 WHEN (bc.je_source_name = 'Other' AND bc.je_category_name = 'Other') THEN
1545 4
1546 END CASE
1547 FROM gl_bc_option_details bc
1548 WHERE bc_option_id = g_bc_option_id);
1549
1550 -- =========================== FND LOG ===========================
1551 psa_utils.debug_other_string(g_state_level,l_full_path, ' l_option_selected -> '||l_option_selected);
1552 -- ========================= FND LOG =============================
1553
1554 INSERT INTO psa_option_details_gt
1555 ( packet_id,
1556 je_source_name,
1557 je_category_name,
1558 gl_bc_option_source,
1559 gl_bc_option_category,
1560 funds_check_level_code,
1561 override_amount,
1562 tolerance_percentage,
1563 tolerance_amount
1564 )
1565 SELECT decode(g_fcmode, 'U', g_packet_id_ursvd, g_packet_id)
1566 ,indx.je_source_name
1567 ,indx.je_category_name
1568 ,decode(l_option_selected,
1569 1, indx.je_source_name,
1570 2, indx.je_source_name,
1571 'Other')
1572 ,decode(l_option_selected,
1573 1, indx.je_category_name,
1574 3, indx.je_category_name,
1575 'Other')
1576 ,funds_check_level_code
1577 ,override_amount
1578 ,tolerance_percentage
1579 ,tolerance_amount
1580 FROM gl_bc_option_details
1581 WHERE bc_option_id = g_bc_option_id
1582 AND je_source_name = decode(l_option_selected,
1583 1, indx.je_source_name,
1584 2, indx.je_source_name,
1585 'Other')
1586 AND je_category_name = decode(l_option_selected,
1587 1, indx.je_category_name,
1588 3, indx.je_category_name,
1589 'Other');
1590
1591 -- =========================== FND LOG ===========================
1592 psa_utils.debug_other_string(g_state_level,l_full_path, sql%rowcount||' Rows Inserted into psa_option_details_gt ');
1593 -- ========================= FND LOG =============================
1594
1595
1596 END LOOP;
1597
1598 -- If Mode is Unreservation, insert Unreservation Packet into the queue
1599 if g_fcmode = 'U' then
1600
1601 -- =========================== FND LOG ===========================
1602 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_fcmode = U ');
1603 -- ========================= FND LOG =============================
1604
1605 if not glxfiu then
1606 -- =========================== FND LOG ===========================
1607 psa_utils.debug_other_string(g_state_level,l_full_path, ' glxfui - RETURN -> FALSE ');
1608 -- ========================= FND LOG =============================
1609 rollback;
1610 return(FALSE);
1611 end if;
1612 end if;
1613
1614 if not glxfss then
1615 -- =========================== FND LOG ===========================
1616 psa_utils.debug_other_string(g_state_level,l_full_path, ' glxfss - RETURN -> FALSE ');
1617 -- ========================= FND LOG =============================
1618 rollback;
1619 return(FALSE);
1620 end if;
1621
1622 if g_overlapping_budget=TRUE then
1623 commit;
1624 return(TRUE);
1625 end if;
1626
1627
1628 -- Check Grants, if extension enabled
1629
1630 gms_retcode := '~';
1631
1632 -- =========================== FND LOG ===========================
1633 psa_utils.debug_other_string(g_state_level,l_full_path, ' gms_retcode -> ' || gms_retcode);
1634 -- ========================= FND LOG =============================
1635
1636 if g_psa_grantcheck then
1637 -- =========================== FND LOG ===========================
1638 psa_utils.debug_other_string(g_state_level,l_full_path, ' Calling glzgchk');
1639 -- ========================= FND LOG =============================
1640 g_psa_grantcheck := glzgchk;
1641 end if;
1642
1643 -- Process Balances
1644
1645 if (g_fcmode <> 'F') then
1646 -- =========================== FND LOG ===========================
1647 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_fcmode <> F');
1648 -- ========================= FND LOG =============================
1649
1650 if not glxfgb then
1651 -- =========================== FND LOG ===========================
1652 psa_utils.debug_other_string(g_state_level,l_full_path, ' glxfgb -> FALSE');
1653 -- ========================= FND LOG =============================
1654 rollback;
1655 return(FALSE);
1656 end if;
1657
1658 end if;
1659
1660 -- ## Update Result Codes
1661 -- ## TROBERTS: Removed Return Code expansion as this applied only
1662 -- ## to the Extended Funds Checker V2 and V3 functionality which
1663 -- ## is not supported in 11.5 and beyond.
1664
1665 if not glxfrc then
1666 -- =========================== FND LOG ===========================
1667 psa_utils.debug_other_string(g_state_level,l_full_path, ' glxfrc -> FALSE');
1668 -- ========================= FND LOG =============================
1669 rollback;
1670 return(FALSE);
1671 end if;
1672
1673 --
1674 -- Need to commit as we exit an autonomous function.
1675 --
1676 commit;
1677
1678 -- =========================== FND LOG ===========================
1679 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN -> TRUE');
1680 -- ========================= FND LOG =============================
1681
1682 return(TRUE);
1683
1684 EXCEPTION
1685
1686 WHEN OTHERS THEN
1687 -- =========================== FND LOG ===========================
1688 psa_utils.debug_other_string(g_excep_level,l_full_path, ' EXCEPTION WHEN OTHERS ' || SQLERRM);
1689 -- ========================= FND LOG =============================
1690
1691 message_token('PROCEDURE', 'Funds Checker');
1692 message_token('EVENT', SQLERRM);
1693 add_message('SQLGL', 'GL_UNHANDLED_EXCEPTION');
1694
1695 g_debug := g_debug||' GLXFCP Failed : '||SQLERRM;
1696 -- Bug 3214062
1697 rollback;
1698
1699 -- =========================== FND LOG ===========================
1700 psa_utils.debug_other_string(g_excep_level,l_full_path, ' RETURN -> TRUE');
1701 -- ========================= FND LOG =============================
1702 return(FALSE);
1703
1704 END glxfcp;
1705
1706 /* ============================== GLXFUG ================================ */
1707
1708 -- Process USSGL Transactions
1709
1710 -- This Module inserts Budgetary or Proprietary actual transactions into
1711 -- the queue table as needed and creates new Budgetary or Proprietary Code
1712 -- Combinations if they do not already exist in the Code Combinations table
1713
1714 FUNCTION glxfug RETURN BOOLEAN IS
1715
1716 l_tmpmsg VARCHAR2(70);
1717 l_rowid VARCHAR2(100);
1718 l_ccid_out NUMBER;
1719 l_ccid NUMBER;
1720
1721 -- Maximum Length for this SQL Statement is 3708
1722
1723 sql_ussgl VARCHAR2(7000);
1724 cur_ussgl INTEGER;
1725 num_ussgl INTEGER;
1726 ignore INTEGER;
1727
1728 segment1 gl_code_combinations.segment1%TYPE;
1729 segment2 gl_code_combinations.segment2%TYPE;
1730 segment3 gl_code_combinations.segment3%TYPE;
1731 segment4 gl_code_combinations.segment4%TYPE;
1732 segment5 gl_code_combinations.segment5%TYPE;
1733 segment6 gl_code_combinations.segment6%TYPE;
1734 segment7 gl_code_combinations.segment7%TYPE;
1735 segment8 gl_code_combinations.segment8%TYPE;
1736 segment9 gl_code_combinations.segment9%TYPE;
1737 segment10 gl_code_combinations.segment10%TYPE;
1738 segment11 gl_code_combinations.segment11%TYPE;
1739 segment12 gl_code_combinations.segment12%TYPE;
1740 segment13 gl_code_combinations.segment13%TYPE;
1741 segment14 gl_code_combinations.segment14%TYPE;
1742 segment15 gl_code_combinations.segment15%TYPE;
1743 segment16 gl_code_combinations.segment16%TYPE;
1744 segment17 gl_code_combinations.segment17%TYPE;
1745 segment18 gl_code_combinations.segment18%TYPE;
1746 segment19 gl_code_combinations.segment19%TYPE;
1747 segment20 gl_code_combinations.segment20%TYPE;
1748 segment21 gl_code_combinations.segment21%TYPE;
1749 segment22 gl_code_combinations.segment22%TYPE;
1750 segment23 gl_code_combinations.segment23%TYPE;
1751 segment24 gl_code_combinations.segment24%TYPE;
1752 segment25 gl_code_combinations.segment25%TYPE;
1753 segment26 gl_code_combinations.segment26%TYPE;
1754 segment27 gl_code_combinations.segment27%TYPE;
1755 segment28 gl_code_combinations.segment28%TYPE;
1756 segment29 gl_code_combinations.segment29%TYPE;
1757 segment30 gl_code_combinations.segment30%TYPE;
1758
1759 cursor ussgl is
1760 select 'USSGL Rows need to be created'
1761 from dual
1762 where exists
1763 (
1764 select 'Transaction with USSGL Code'
1765 from gl_bc_packets bp
1766 where bp.packet_id = g_packet_id
1767 and bp.ussgl_transaction_code is not null
1768 );
1769
1770 cursor append_je is
1771 select 'Associated Generated JEs to be appended or inserted'
1772 from dual
1773 where exists
1774 (
1775 select 'Associated Generated Row from existing GL Batch'
1776 from gl_bc_packets bp
1777 where bp.packet_id = g_packet_id
1778 and bp.je_batch_id is not null
1779 and bp.je_batch_id >= 0
1780 and bp.ussgl_transaction_code is not null
1781 );
1782
1783 -- ========================= FND LOG ===========================
1784 l_full_path VARCHAR2(100);
1785 -- ========================= FND LOG ===========================
1786 BEGIN
1787
1788 l_full_path := g_path || 'glxfug';
1789
1790 -- =========================== FND LOG ===========================
1791 psa_utils.debug_other_string(g_state_level,l_full_path, ' GLXFUG - START' );
1792 -- ========================= FND LOG =============================
1793
1794 -- Check that USSGL transactions need to be created since the overhead for
1795 -- constructing and executing the Dynamic SQL for inserting USSGL
1796 -- Transactions is much higher than this check
1797
1798 open ussgl;
1799
1800 fetch ussgl into l_tmpmsg;
1801
1802 -- =========================== FND LOG ===========================
1803 psa_utils.debug_other_string(g_state_level,l_full_path, ' l_tmpmsg -> ' || l_tmpmsg );
1804 -- ========================= FND LOG =============================
1805
1806 -- No USSGL Transactions need to be created
1807 if ussgl%NOTFOUND then
1808 -- =========================== FND LOG ===========================
1809 psa_utils.debug_other_string(g_state_level,l_full_path, ' goto normal_exit label' );
1810 -- ========================= FND LOG =============================
1811 goto normal_exit;
1812 end if;
1813
1814 close ussgl;
1815
1816 -- Check if there are associated generated Journal Entry lines
1817 -- to be appended to an existing Actual Batch or if a separate
1818 -- Actual Batch would need to be created if the Originating
1819 -- source is an existing Encumbrance Batch
1820
1821 open append_je;
1822 fetch append_je into l_tmpmsg;
1823
1824 if append_je%FOUND then
1825 -- =========================== FND LOG ===========================
1826 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_append_je_flag -> TRUE');
1827 -- ========================= FND LOG =============================
1828 g_append_je_flag := TRUE;
1829 else
1830 -- =========================== FND LOG ===========================
1831 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_append_je_flag -> FALSE');
1832 -- ========================= FND LOG =============================
1833 g_append_je_flag := FALSE;
1834 end if;
1835
1836 close append_je;
1837
1838
1839 UPDATE GL_BC_PACKETS BP
1840 SET BP.ussgl_parent_id = GL_USSGL_PARENT_S.NEXTVAL
1841 WHERE
1842 BP.packet_id = g_packet_id
1843 AND BP.ussgl_transaction_code IS NOT NULL;
1844
1845 -- =========================== FND LOG ===========================
1846 psa_utils.debug_other_string(g_state_level,l_full_path, ' Update gl_bc_packets -> ' || SQL%ROWCOUNT );
1847 -- ========================= FND LOG =============================
1848
1849 if g_append_je_flag then
1850
1851 -- ## ----------------------------------------------------------+
1852 -- ## Bug: 1387967/2178715 Federal AR |
1853 -- ## Drill down of USSGL generated transactions to AR. |
1854 -- ## ----------------------------------------------------------+
1855
1856 UPDATE GL_BC_PACKETS BP
1857 SET
1858 ( BP.reference1,
1859 BP.reference2,
1860 BP.reference3,
1861 BP.reference4,
1862 BP.reference5,
1863 BP.reference6,
1864 BP.reference7,
1865 BP.reference8,
1866 BP.reference9,
1867 BP.reference10) =
1868 (SELECT GI.reference_1,
1869 GI.reference_2,
1870 GI.reference_3,
1871 GI.reference_4,
1872 GI.reference_5,
1873 GI.reference_6,
1874 GI.reference_7,
1875 GI.reference_8,
1876 GI.reference_9,
1877 GI.reference_10
1878 FROM gl_import_references GI
1879 WHERE GI.je_line_num = BP.je_line_num
1880 AND GI.je_header_id= BP.je_header_id
1881 AND GI.je_batch_id = BP.je_batch_id)
1882 WHERE
1883 BP.packet_id = g_packet_id
1884 AND BP.ussgl_transaction_code IS NOT NULL;
1885
1886 end if;
1887
1888 -- =========================== FND LOG ===========================
1889 psa_utils.debug_other_string(g_state_level,l_full_path, ' Update gl_bc_packets -> ' || SQL%ROWCOUNT );
1890 psa_utils.debug_other_string(g_state_level,l_full_path, 'Calling glxfkf' );
1891 -- ========================= FND LOG =============================
1892
1893 -- Retrieve Flex Info for the Flex Structure
1894 if not glxfkf then
1895 -- =========================== FND LOG ===========================
1896 psa_utils.debug_other_string(g_state_level,l_full_path, ' glxfkf ->False --> RETURN FALSE' );
1897 -- ========================= FND LOG =============================
1898 return(FALSE);
1899 end if;
1900
1901
1902 -- Insertion of USSGL transactions into gl_bc_packets
1903
1904 -- When the USSGL Option is set, this process is executed prior to setting
1905 -- up of the denormalized columns and this applies to Funds Check and
1906 -- Funds Reservation. For all packet transactions with a USSGL transaction
1907 -- code, this function creates all the required budgetary or proprietary
1908 -- actual transaction records depending on the USSGL transaction codes and
1909 -- the associated Debit and Credit Account Segment values pair defined in
1910 -- gl_ussgl_account_pairs
1911
1912 -- The number of additional transactions generated for each originating
1913 -- transaction equals the number of Debit and Credit Account Segment
1914 -- values associated with the originating USSGL transaction code. For
1915 -- example, if there are 3 Proprietary transactions with non-null USSGL
1916 -- transaction codes in the packet, and for each of the codes, 2 Debit and
1917 -- Credit Account Pairs have been defined, then the number of additional
1918 -- transactions generated will be 12 (3 transactions * 2 acct pairs/code *
1919 -- 2 acct/pair). No Consolidation is done for multiple generated
1920 -- generated transactions with the same account
1921
1922 -- The Entered and Accounted amount columns for the generated transactions
1923 -- are filled up as follows :
1924 --
1925 -- Originating Generated Generated
1926 -- Transaction Debit Transaction Credit Transaction
1927 -- Account Type DR CR DR CR
1928 -- ------------ ----------------- ------------------
1929 -- 'A', 'E', 'D' O_DR O_CR O_CR O_DR
1930 --
1931 -- 'L', 'O', 'R', 'C' O_CR O_DR O_DR O_CR
1932 --
1933 -- O_DR : Entered/Accounted Debit Amount for Originating Transaction
1934 -- O_CR : Entered/Accounted Credit Amount for Originating Transaction
1935
1936 -- Bug 3111554:
1937 -- If profile GL_REVERSE_TC_OPTION = 'N' then entered and accounted
1938 -- amounts are derived as follows.
1939
1940 -- decode(nvl(PET.event_type, 'X'),
1941 -- lu.lookup_code, BP.entered_dr,
1942 -- 'X', decode(CCO.account_type || LU.lookup_code,
1943 -- 'AD', BP.entered_dr,
1944 -- 'ED', BP.entered_dr,
1945 -- 'DD', BP.entered_dr,
1946 -- 'LC', BP.entered_dr,
1947 -- 'OC', BP.entered_dr,
1948 -- 'RC', BP.entered_dr,
1949 -- 'CC', BP.entered_dr,
1950 -- BP.entered_cr),
1951 -- BP.entered_cr),
1952 -- decode(nvl(PET.event_type, 'X'),
1953 -- lu.lookup_code, BP.entered_cr,
1954 -- 'X', decode(CCO.account_type LU.lookup_code,
1955 -- 'AD', BP.entered_cr,
1956 -- 'ED', BP.entered_cr,
1957 -- 'DD', BP.entered_cr,
1958 -- 'LC', BP.entered_cr,
1959 -- 'OC', BP.entered_cr,
1960 -- 'RC', BP.entered_cr,
1961 -- 'CC', BP.entered_cr,
1962 -- BP.entered_dr),
1963 -- BP.entered_dr)
1964
1965 -- When the Code Combination for a generated transaction does not exist,
1966 -- the transaction is created and the CCID is initialized to the negative
1967 -- value of the originating transaction's CCID. These transactions are
1968 -- then inserted into the Code Combinations table with new CCIDs
1969
1970 sql_ussgl := 'insert into gl_bc_packets (packet_id, ' ||
1971 'ledger_id, ' ||
1972 'je_source_name, ' ||
1973 'je_category_name, ' ||
1974 'code_combination_id, ' ||
1975 'actual_flag, ' ||
1976 'period_name, ' ||
1977 'period_year, ' ||
1978 'period_num, ' ||
1979 'quarter_num, ' ||
1980 'currency_code, ' ||
1981 'status_code, ' ||
1982 'last_update_date, ' ||
1983 'last_updated_by, ' ||
1984 'entered_dr, ' ||
1985 'entered_cr, ' ||
1986 'accounted_dr, ' ||
1987 'accounted_cr, ' ||
1988 'originating_rowid, ' ||
1989 'account_segment_value, ' ||
1990 'je_batch_name, ' ||
1991 'je_batch_id, ' ||
1992 'je_header_id, ' ||
1993 'je_line_num, '||
1994 'reference1, ' ||
1995 'reference2, ' ||
1996 'reference3, ' ||
1997 'reference4, ' ||
1998 'reference5, ' ||
1999 'reference6, ' ||
2000 'reference7, ' ||
2001 'reference8, ' ||
2002 'reference9, ' ||
2003 'reference10, '||
2004 'ussgl_link_to_parent_id, '||
2005 'session_id, '||
2006 'serial_id, ' ||
2007 'application_id) ';
2008
2009 sql_ussgl := sql_ussgl ||
2010 'select bp.packet_id, ' ||
2011 'bp.ledger_id, ' ||
2012 'bp.je_source_name, ' ||
2013 'bp.je_category_name, ' ||
2014 'decode(ccg.code_combination_id, ' ||
2015 'cco.code_combination_id, ' ||
2016 '-1 * cco.code_combination_id, ' ||
2017 'ccg.code_combination_id), ' ||
2018 '''A'', ' ||
2019 'bp.period_name, ' ||
2020 'bp.period_year, ' ||
2021 'bp.period_num, ' ||
2022 'bp.quarter_num, ' ||
2023 'bp.currency_code, ' ||
2024 'bp.status_code, ' ||
2025 'bp.last_update_date, ' ||
2026 'bp.last_updated_by, ';
2027
2028 -- =========================== FND LOG ===========================
2029 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_reverse_tc_flag -> ' || g_reverse_tc_flag );
2030 -- ========================= FND LOG =============================
2031
2032 if g_reverse_tc_flag = 'N' then
2033
2034 sql_ussgl := sql_ussgl ||
2035 'decode(nvl(PET.event_type, ''X''), ' ||
2036 'lu.lookup_code, BP.entered_dr,' ||
2037 '''X'', decode(CCO.account_type || LU.lookup_code,' ||
2038 '''AD'', BP.entered_dr, ' ||
2039 '''ED'', BP.entered_dr, ' ||
2040 '''DD'', BP.entered_dr, ' ||
2041 '''LC'', BP.entered_dr, ' ||
2042 '''OC'', BP.entered_dr, ' ||
2043 '''RC'', BP.entered_dr, ' ||
2044 '''CC'', BP.entered_dr, BP.entered_cr), ' ||
2045 'BP.entered_cr),' ||
2046 'decode(nvl(PET.event_type, ''X''), ' ||
2047 'lu.lookup_code, BP.entered_cr,' ||
2048 '''X'', decode(CCO.account_type || LU.lookup_code,' ||
2049 '''AD'', BP.entered_cr, ' ||
2050 '''ED'', BP.entered_cr, ' ||
2051 '''DD'', BP.entered_cr, ' ||
2052 '''LC'', BP.entered_cr, ' ||
2053 '''OC'', BP.entered_cr, ' ||
2054 '''RC'', BP.entered_cr, ' ||
2055 '''CC'', BP.entered_cr, BP.entered_dr),' ||
2056 'BP.entered_dr),' ||
2057 'decode(nvl(PET.event_type, ''X''),' ||
2058 'lu.lookup_code, BP.accounted_dr,' ||
2059 '''X'', decode(CCO.account_type || LU.lookup_code,' ||
2060 '''AD'', BP.accounted_dr, ' ||
2061 '''ED'', BP.accounted_dr, ' ||
2062 '''DD'', BP.accounted_dr, ' ||
2063 '''LC'', BP.accounted_dr, ' ||
2064 '''OC'', BP.accounted_dr, ' ||
2065 '''RC'', BP.accounted_dr, ' ||
2066 '''CC'', BP.accounted_dr, BP.accounted_cr),' ||
2067 'BP.accounted_cr),' ||
2068 'decode(nvl(PET.event_type, ''X''),' ||
2069 'lu.lookup_code, BP.accounted_cr,' ||
2070 '''X'', decode(CCO.account_type || LU.lookup_code,' ||
2071 '''AD'', BP.accounted_cr, ' ||
2072 '''ED'', BP.accounted_cr, ' ||
2073 '''DD'', BP.accounted_cr, ' ||
2074 '''LC'', BP.accounted_cr, ' ||
2075 '''OC'', BP.accounted_cr, ' ||
2076 '''RC'', BP.accounted_cr, ' ||
2077 '''CC'', BP.accounted_cr, BP.accounted_dr),' ||
2078 'BP.accounted_dr), ';
2079 else
2080
2081
2082 sql_ussgl := sql_ussgl ||
2083 'decode(cco.account_type || lu.lookup_code, ' ||
2084 '''AD'', bp.entered_dr, ' ||
2085 '''ED'', bp.entered_dr, ' ||
2086 '''DD'', bp.entered_dr, ' ||
2087 '''LC'', bp.entered_dr, ' ||
2088 '''OC'', bp.entered_dr, ' ||
2089 '''RC'', bp.entered_dr, ' ||
2090 '''CC'', bp.entered_dr, bp.entered_cr), ' ||
2091 'decode(cco.account_type || lu.lookup_code, ' ||
2092 '''AD'', bp.entered_cr, ' ||
2093 '''ED'', bp.entered_cr, ' ||
2094 '''DD'', bp.entered_cr, ' ||
2095 '''LC'', bp.entered_cr, ' ||
2096 '''OC'', bp.entered_cr, ' ||
2097 '''RC'', bp.entered_cr, ' ||
2098 '''CC'', bp.entered_cr, bp.entered_dr), ' ||
2099 'decode(cco.account_type || lu.lookup_code, ' ||
2100 '''AD'', bp.accounted_dr, ' ||
2101 '''ED'', bp.accounted_dr, ' ||
2102 '''DD'', bp.accounted_dr, ' ||
2103 '''LC'', bp.accounted_dr, ' ||
2104 '''OC'', bp.accounted_dr, ' ||
2105 '''RC'', bp.accounted_dr, ' ||
2106 '''CC'', bp.accounted_dr, bp.accounted_cr), ' ||
2107 'decode(cco.account_type || lu.lookup_code, ' ||
2108 '''AD'', bp.accounted_cr, ' ||
2109 '''ED'', bp.accounted_cr, ' ||
2110 '''DD'', bp.accounted_cr, ' ||
2111 '''LC'', bp.accounted_cr, ' ||
2112 '''OC'', bp.accounted_cr, ' ||
2113 '''RC'', bp.accounted_cr, ' ||
2114 '''CC'', bp.accounted_cr, bp.accounted_dr), ';
2115 end if;
2116
2117 sql_ussgl := sql_ussgl ||
2118 'bp.rowid, ' ||
2119 'decode(ccg.code_combination_id, ' ||
2120 'cco.code_combination_id, ' ||
2121 'decode(lu.lookup_code, ' ||
2122 '''D'', guap.dr_account_segment_value, ' ||
2123 '''C'', guap.cr_account_segment_value), ' ||
2124 'ccg.' || seg_name(g_acct_seg_index) || '), ' ||
2125 'bp.je_batch_name, ' ||
2126 'bp.je_batch_id, ' ||
2127 'bp.je_header_id, ' ||
2128 'bp.je_line_num, '||
2129 'bp.reference1, ' ||
2130 'bp.reference2, ' ||
2131 'bp.reference3, ' ||
2132 'bp.reference4, ' ||
2133 'bp.reference5, ' ||
2134 'bp.reference6, ' ||
2135 'bp.reference7, ' ||
2136 'bp.reference8, ' ||
2137 'bp.reference9, ' ||
2138 'bp.reference10, '||
2139 'bp.ussgl_parent_id, '||
2140 'g_session_id, '||
2141 'g_serial_id, '||
2142 'g_resp_appl_id ';
2143
2144 if g_reverse_tc_flag = 'N' then
2145
2146 sql_ussgl := sql_ussgl ||
2147 'from gl_lookups lu, ' ||
2148 'gl_ussgl_transaction_codes uc, ' ||
2149 'gl_ussgl_account_pairs guap, ' ||
2150 'gl_code_combinations ccg, ' ||
2151 'gl_code_combinations cco, ' ||
2152 'gl_bc_packets bp, ' ||
2153 'psa_event_types pet ' ||
2154 'where lu.lookup_type = ''DR_CR'' ' ||
2155 'and pet.je_source (+) = bp.je_source_name ' ||
2156 -- modified for bug 4167009
2157 'and pet.je_category (+) = ' ||
2158 ' decode(bp.je_category_name, '|| '''Payments'','||
2159 'decode(substr(bp.reference5, instr(bp.reference5,' ||'''-'', -1,1)+1, 3),'||
2160 '''INT'' ,'|| '''Purchase Invoices'','||
2161 'bp.je_category_name), bp.je_category_name )' ||
2162 'and uc.chart_of_accounts_id = ' ||
2163 'guap.chart_of_accounts_id ' ||
2164 'and uc.ussgl_transaction_code = ' ||
2165 'bp.ussgl_transaction_code ' ||
2166 'and sysdate between ' ||
2167 'nvl(uc.start_date_active, sysdate) ' ||
2168 'and nvl(uc.end_date_active, sysdate) ' ||
2169 'and guap.chart_of_accounts_id = ' || g_coa_id || ' ' ||
2170 'and guap.ussgl_transaction_code = ' ||
2171 'bp.ussgl_transaction_code ' ||
2172 'and ccg.code_combination_id = ' ||
2173 '(' ||
2174 'select nvl(min(ccg1.code_combination_id), ' ||
2175 'cco.code_combination_id) ' ||
2176 'from gl_code_combinations ccg1 ' ||
2177 'where ccg1.chart_of_accounts_id = ' ||
2178 g_coa_id;
2179 else
2180
2181 sql_ussgl := sql_ussgl ||
2182
2183 'from gl_lookups lu, ' ||
2184 'gl_ussgl_transaction_codes uc, ' ||
2185 'gl_ussgl_account_pairs guap, ' ||
2186 'gl_code_combinations ccg, ' ||
2187 'gl_code_combinations cco, ' ||
2188 'gl_bc_packets bp ' ||
2189 'where lu.lookup_type = ''DR_CR'' ' ||
2190 'and uc.chart_of_accounts_id = ' ||
2191 'guap.chart_of_accounts_id ' ||
2192 'and uc.ussgl_transaction_code = ' ||
2193 'bp.ussgl_transaction_code ' ||
2194 'and sysdate between ' ||
2195 'nvl(uc.start_date_active, sysdate) ' ||
2196 'and nvl(uc.end_date_active, sysdate) ' ||
2197 'and guap.chart_of_accounts_id = ' || g_coa_id || ' ' ||
2198 'and guap.ussgl_transaction_code = ' ||
2199 'bp.ussgl_transaction_code ' ||
2200 'and ccg.code_combination_id = ' ||
2201 '(' ||
2202 'select nvl(min(ccg1.code_combination_id), ' ||
2203 'cco.code_combination_id) ' ||
2204 'from gl_code_combinations ccg1 ' ||
2205 'where ccg1.chart_of_accounts_id = ' ||
2206 g_coa_id;
2207 end if;
2208
2209
2210 for i in 1..g_num_segs loop
2211
2212 if seg_name(i) is not null then
2213
2214 if (i <> g_acct_seg_index) then
2215 sql_ussgl := sql_ussgl ||
2216 ' and ccg1.' || seg_name(i) || ' = ' ||
2217 'cco.' || seg_name(i);
2218 else
2219 sql_ussgl := sql_ussgl ||
2220 ' and ccg1.' || seg_name(i) || ' = ' ||
2221 'decode(lu.lookup_code, ' ||
2222 '''D'', guap.dr_account_segment_value, ' ||
2223 '''C'', guap.cr_account_segment_value)';
2224 end if;
2225
2226 end if;
2227
2228 end loop;
2229
2230 sql_ussgl := sql_ussgl ||
2231 ') ' ||
2232 'and cco.code_combination_id = bp.code_combination_id ' ||
2233 'and bp.packet_id = ' || g_packet_id || ' ' ||
2234 'and bp.ussgl_transaction_code is not null';
2235
2236 -- =========================== FND LOG ===========================
2237 psa_utils.debug_other_string(g_state_level,l_full_path, ' sql_ussgl -> ' || SUBSTR(sql_ussgl,1,3500));
2238 psa_utils.debug_other_string(g_state_level,l_full_path, ' sql_ussgl -> ' || SUBSTR(sql_ussgl,3500,7000));
2239 -- ========================= FND LOG =============================
2240
2241 execute immediate sql_ussgl;
2242
2243 -- =========================== FND LOG ===========================
2244 psa_utils.debug_other_string(g_state_level,l_full_path, 'USSGL Rows Inserted: '||sql%rowcount);
2245 -- ========================= FND LOG =============================
2246
2247 -- Now that the USSGL Transactions have been generated in the queue, we
2248 -- pick up the Code Combinations which need to be created in the Code
2249 -- Combinations table
2250
2251 sql_ussgl := 'select DISTINCT ';
2252
2253 -- Call Flex API for inserting a new combination of Segment Values
2254
2255 for i in 1..g_num_segs loop
2256
2257 if (i <> g_acct_seg_index) then
2258 sql_ussgl := sql_ussgl ||
2259 seg_name(i) || ', ';
2260 else
2261 sql_ussgl := sql_ussgl ||
2262 'bp.account_segment_value, ';
2263 end if;
2264
2265 end loop;
2266
2267 sql_ussgl := sql_ussgl ||
2268 'bp.code_combination_id ' ||
2269 'from gl_code_combinations cc, ' ||
2270 'gl_bc_packets bp ' ||
2271 'where cc.code_combination_id = -1 * bp.code_combination_id ' ||
2272 'and bp.packet_id = ' || g_packet_id || ' ' ||
2273 'and bp.code_combination_id < 0 ' ||
2274 'and bp.account_segment_value is not null';
2275
2276 -- =========================== FND LOG ===========================
2277 psa_utils.debug_other_string(g_state_level,l_full_path, ' sql_ussgl1 -> ' || SUBSTR(sql_ussgl,1,3500));
2278 psa_utils.debug_other_string(g_state_level,l_full_path, ' sql_ussgl1 -> ' || SUBSTR(sql_ussgl,3500,7000));
2279 -- ========================= FND LOG =============================
2280
2281 cur_ussgl := dbms_sql.open_cursor;
2282 dbms_sql.parse(cur_ussgl, sql_ussgl, dbms_sql.v7);
2283
2284 for i in 1..g_num_segs loop
2285 dbms_sql.define_column(cur_ussgl, i, 'segment' || i, 30);
2286 end loop;
2287
2288 dbms_sql.define_column(cur_ussgl, g_num_segs + 1, l_ccid);
2289
2290 ignore := dbms_sql.execute(cur_ussgl);
2291
2292 loop
2293
2294 if dbms_sql.fetch_rows(cur_ussgl) > 0 then
2295
2296 for i in 1..g_num_segs loop
2297 dbms_sql.column_value(cur_ussgl, i, seg_val(i));
2298 end loop;
2299
2300 dbms_sql.column_value(cur_ussgl, g_num_segs + 1, l_ccid);
2301
2302 if not FND_FLEX_EXT.GET_COMBINATION_ID('SQLGL', 'GL#', g_coa_id,
2303 sysdate, g_num_segs, seg_val, l_ccid_out) then
2304 goto return_invalid;
2305 end if;
2306
2307
2308 -- Commit to allow other Users to create similar combinations on any
2309 -- flexfield
2310
2311 commit;
2312
2313
2314 -- Update the CCID of the USSGL transaction in the Packet
2315
2316 update gl_bc_packets bp
2317 set bp.code_combination_id = l_ccid_out
2318 where bp.code_combination_id = l_ccid
2319 and bp.account_segment_value=seg_val(g_acct_seg_index);
2320
2321 -- =========================== FND LOG ===========================
2322 psa_utils.debug_other_string(g_state_level,l_full_path, ' update gl_bc_packets -> ' || SQL%ROWCOUNT);
2323 -- ========================= FND LOG =============================
2324
2325 else
2326 exit;
2327 end if;
2328
2329 end loop;
2330
2331 dbms_sql.close_cursor(cur_ussgl);
2332
2333 -- =========================== FND LOG ===========================
2334 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_fcmode -> ' || g_fcmode);
2335 -- ========================= FND LOG =============================
2336
2337 -- Exit Function if Mode is Check
2338 if g_fcmode = 'C' then
2339 -- =========================== FND LOG ===========================
2340 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_fcmode = C -> goto normal_exit label');
2341 -- ========================= FND LOG =============================
2342 goto normal_exit;
2343 end if;
2344
2345 -- =========================== FND LOG ===========================
2346 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_fcmode != C -> RETURN TRUE');
2347 -- ========================= FND LOG =============================
2348
2349 return(TRUE);
2350
2351 <<normal_exit>>
2352
2353 -- =========================== FND LOG ===========================
2354 psa_utils.debug_other_string(g_state_level,l_full_path, ' reached normal_exit label ');
2355 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN -> TRUE ');
2356 -- ========================= FND LOG =============================
2357
2358 if ussgl%ISOPEN then
2359 close ussgl;
2360 end if;
2361
2362 return(TRUE);
2363
2364 <<return_invalid>>
2365
2366 -- =========================== FND LOG ===========================
2367 psa_utils.debug_other_string(g_state_level,l_full_path, ' reached return_invalid label ');
2368 -- ========================= FND LOG =============================
2369
2370 if dbms_sql.is_open(cur_ussgl) then
2371 dbms_sql.close_cursor(cur_ussgl);
2372 end if;
2373
2374 message_token('PROCEDURE', 'Funds Checker');
2375 message_token('EVENT', FND_MESSAGE.GET_ENCODED);
2376 add_message('SQLGL', 'GL_UNHANDLED_EXCEPTION');
2377
2378 -- =========================== FND LOG ===========================
2379 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN -> FALSE ');
2380 -- ========================= FND LOG =============================
2381
2382 g_debug := g_debug||' GLXFUG Failed : FND_FLEX_EXT.GET_COMBINATION_ID returned FALSE';
2383
2384 return(FALSE);
2385
2386
2387 EXCEPTION
2388
2389 WHEN OTHERS THEN
2390
2391 -- =========================== FND LOG ===========================
2392 psa_utils.debug_other_string(g_excep_level,l_full_path, ' WHEN OTHERS EXCEPTION ' || SQLERRM);
2393 -- ========================= FND LOG =============================
2394
2395 if ussgl%ISOPEN then
2396 close ussgl;
2397 end if;
2398
2399 if dbms_sql.is_open(cur_ussgl) then
2400 dbms_sql.close_cursor(cur_ussgl);
2401 end if;
2402
2403 if append_je%ISOPEN then
2404 close append_je;
2405 end if;
2406
2407 message_token('PROCEDURE', 'Funds Checker');
2408 message_token('EVENT', SQLERRM);
2409 add_message('SQLGL', 'GL_UNHANDLED_EXCEPTION');
2410
2411 -- =========================== FND LOG ===========================
2412 psa_utils.debug_other_string(g_excep_level,l_full_path, ' RETURN -> FALSE ');
2413 -- ========================= FND LOG =============================
2414
2415 g_debug := g_debug||' GLXFUG Failed : '||SQLERRM;
2416 return(FALSE);
2417
2418 END glxfug;
2419
2420 /* =========================== GLXFKF ========================= */
2421
2422 -- Retrieve Flex Info for the Flex Structure
2423 -- This Function retrieves Flex Info such as Active Segment Info and the
2424 -- Accounting Segment Index
2425
2426 FUNCTION glxfkf RETURN BOOLEAN IS
2427
2428 others EXCEPTION;
2429
2430 cursor seginfo(appl_id NUMBER,
2431 flex_code VARCHAR2,
2432 flex_num NUMBER) is
2433 select application_column_name
2434 from fnd_id_flex_segments
2435 where application_id = appl_id
2436 and id_flex_code = flex_code
2437 and id_flex_num = flex_num
2438 and enabled_flag = 'Y'
2439 order by segment_num;
2440
2441 -- ========================= FND LOG ===========================
2442 l_full_path VARCHAR2(100);
2443 -- ========================= FND LOG ===========================
2444 BEGIN
2445
2446 l_full_path := g_path || 'glxfkf';
2447
2448 -- =========================== FND LOG ===========================
2449 psa_utils.debug_other_string(g_state_level,l_full_path, ' GLXFUF - START' );
2450 -- ========================= FND LOG =============================
2451
2452 -- Retrieve Active Segment Info
2453 for c_seginfo in seginfo(101, 'GL#', g_coa_id) loop
2454 g_num_segs := g_num_segs + 1;
2455 seg_name(g_num_segs) := c_seginfo.application_column_name;
2456 end loop;
2457
2458 -- Get Cardinal Order or Index Number of the Account Segment
2459 if not FND_FLEX_APIS.GET_QUALIFIER_SEGNUM(101,
2460 'GL#',
2461 g_coa_id,
2462 'GL_ACCOUNT',
2463 g_acct_seg_index) then
2464 message_token('ROUTINE', 'GL_FC_PKG');
2465 add_message('FND', 'FLEXGL-NO ACCT SEG');
2466 -- =========================== FND LOG ===========================
2467 psa_utils.debug_other_string(g_state_level,l_full_path, ' RAISE OTHERS ' );
2468 -- ========================= FND LOG =============================
2469 g_debug := g_debug||' GLXFKF Failed : FND_FLEX_APIS.GET_QUALIFIER_SEGNUM returned FALSE';
2470 raise others;
2471 end if;
2472
2473 -- =========================== FND LOG ===========================
2474 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_acct_seg_index -> ' || g_acct_seg_index );
2475 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN -> TRUE ');
2476 -- ========================= FND LOG =============================
2477
2478 return(TRUE);
2479
2480
2481 EXCEPTION
2482
2483 WHEN OTHERS THEN
2484 -- =========================== FND LOG ===========================
2485 psa_utils.debug_other_string(g_excep_level,l_full_path, ' EXCEPTION WHEN OTHERS' || SQLERRM );
2486 -- ========================= FND LOG =============================
2487
2488 message_token('PROCEDURE', 'Funds Checker');
2489 message_token('EVENT', SQLERRM);
2490 add_message('SQLGL', 'GL_UNHANDLED_EXCEPTION');
2491
2492 -- =========================== FND LOG ===========================
2493 psa_utils.debug_other_string(g_excep_level,l_full_path, ' RETURN -> FALSE' );
2494 -- ========================= FND LOG =============================
2495
2496 g_debug := g_debug||' GLXFKF Failed : '||SQLERRM;
2497 return(FALSE);
2498
2499 END glxfkf;
2500
2501 /* =========================== GLXFIU =============================== */
2502
2503 -- Insert Unreservation Packet into the Queue
2504
2505 -- All transactions including associated generated transactions are created
2506 -- out of the packet being unreserved by copying over most of the column
2507 -- values with the exception of the amount and denormalized column values.
2508 -- For the Amount columns, the Debit and Credit values are swapped to create
2509 -- a reversal effect while the denormalized columns like Tolerance and
2510 -- Override info are retrieved from the existing system settings. This is to
2511 -- facilitate cases where there is a need to overcome a Funds Reservation
2512 -- failure by modifying the Tolerance/Override Settings in the Budgetary
2513 -- Control Options. The tie-back mechanism for the originating and associated
2514 -- generated transactions, originating_rowid in the generated lines, are also
2515 -- preserved in the unreservation packet through a separate update SQL
2516
2517 -- Summary transactions, as for normal Check/Reservation packets, are derived
2518 -- through the summarization logic in glxfss(). This is feasible because of
2519 -- the tightly coupled locking mechanism between the Funds Checker and the
2520 -- Add/Delete Summary Accounts program, and the packet resummarization
2521 -- logic in glxfrs(), which guarantees that all summary lines in all the
2522 -- approved packets will always reflect the most current summarization
2523 -- structures defined
2524
2525 -- Validations normally performed for a Check/Reservation packet in glxfss()
2526 -- denormalization logic are ignored here. Any validation violations that
2527 -- that arise after the Original Packet has been successfully reserved are
2528 -- assumed to be insignificant as these reversal entries are only intended to
2529 -- back out Funds that have been Reserved but is not used for posting
2530
2531 FUNCTION glxfiu RETURN BOOLEAN IS
2532
2533 cursor pkt_id is
2534 select gl_bc_packets_s.nextval
2535 from dual;
2536
2537 l_dummy VARCHAR2(80);
2538
2539 -- ========================= FND LOG ===========================
2540 l_full_path VARCHAR2(100);
2541 -- ========================= FND LOG ===========================
2542 BEGIN
2543
2544 l_full_path := g_path || 'glxfiu.';
2545
2546 -- =========================== FND LOG ===========================
2547 psa_utils.debug_other_string(g_state_level,l_full_path, ' GLXFUI - START' );
2548 -- ========================= FND LOG =============================
2549
2550 open pkt_id;
2551 fetch pkt_id into g_packet_id;
2552 close pkt_id;
2553
2554 -- =========================== FND LOG ===========================
2555 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_packet_id -> ' || g_packet_id );
2556 -- ========================= FND LOG =============================
2557
2558 -- Insert Unreservation Packet into gl_bc_packets
2559 insert into gl_bc_packets
2560 (packet_id,
2561 ledger_id,
2562 je_source_name,
2563 je_category_name,
2564 code_combination_id,
2565 actual_flag,
2566 period_name,
2567 period_year,
2568 period_num,
2569 quarter_num,
2570 currency_code,
2571 status_code,
2572 last_update_date,
2573 last_updated_by,
2574 budget_version_id,
2575 encumbrance_type_id,
2576 entered_dr,
2577 entered_cr,
2578 accounted_dr,
2579 accounted_cr,
2580 ussgl_transaction_code,
2581 originating_rowid,
2582 automatic_encumbrance_flag,
2583 funding_budget_version_id,
2584 funds_check_level_code,
2585 amount_type,
2586 boundary_code,
2587 tolerance_percentage,
2588 tolerance_amount,
2589 override_amount,
2590 account_type,
2591 dr_cr_code,
2592 account_category_code,
2593 effect_on_funds_code,
2594 je_batch_id,
2595 je_header_id,
2596 je_line_num,
2597 ussgl_parent_id,
2598 ussgl_link_to_parent_id,
2599 session_id,
2600 serial_id,
2601 application_id)
2602 select g_packet_id,
2603 bp.ledger_id,
2604 bp.je_source_name,
2605 bp.je_category_name,
2606 bp.code_combination_id,
2607 bp.actual_flag,
2608 bp.period_name,
2609 bp.period_year,
2610 bp.period_num,
2611 bp.quarter_num,
2612 bp.currency_code,
2613 'P',
2614 sysdate,
2615 g_user_id,
2616 bp.budget_version_id,
2617 bp.encumbrance_type_id,
2618 bp.entered_cr,
2619 bp.entered_dr,
2620 bp.accounted_cr,
2621 bp.accounted_dr,
2622 bp.ussgl_transaction_code,
2623 nvl(bp.originating_rowid,
2624 decode(bp.ussgl_transaction_code, NULL, NULL, bp.rowid)),
2625 -- decode(bp.account_type, 'C', g_budgetary_enc_flag,
2626 -- 'D', g_budgetary_enc_flag,
2627 -- nvl(ba.automatic_encumbrance_flag,
2628 -- bp.automatic_encumbrance_flag)),
2629 'Y',
2630 nvl(bo.funding_budget_version_id, bp.funding_budget_version_id),
2631 decode(bo.funds_check_level_code, null,
2632 bp.funds_check_level_code,
2633 'D', nvl(od.funds_check_level_code, 'D'),
2634 bo.funds_check_level_code),
2635 nvl(bo.amount_type, bp.amount_type),
2636 nvl(bo.boundary_code, bp.boundary_code),
2637 od.tolerance_percentage,
2638 od.tolerance_amount,
2639 od.override_amount,
2640 bp.account_type,
2641 bp.dr_cr_code,
2642 bp.account_category_code,
2643 decode(
2644 decode(bp.actual_flag || bp.dr_cr_code ||
2645 bp.account_category_code, 'BCP', 'dec', 'ADP', 'dec',
2646 'EDP', 'dec', 'ACB', 'dec', 'BCB', 'n/a', 'BDB', 'n/a',
2647 'ECB', 'n/a', 'EDB', 'n/a',
2648 'PDP', 'dec',
2649 'PCB', 'dec', 'FDP', 'dec','FCB', 'n/a', 'FDB','n/a','inc'
2650 ),
2651 'dec', decode(sign(nvl(bp.accounted_cr, 0) -
2652 nvl(bp.accounted_dr, 0)), 1, 'D', 'I'),
2653 'inc', decode(sign(nvl(bp.accounted_cr, 0) -
2654 nvl(bp.accounted_dr, 0)), -1, 'D', 'I'),
2655 'n/a', 'I'),
2656 bp.je_batch_id,
2657 bp.je_header_id,
2658 bp.je_line_num,
2659 bp.ussgl_parent_id,
2660 bp.ussgl_link_to_parent_id,
2661 g_session_id,
2662 g_serial_id,
2663 g_resp_appl_id
2664 from psa_option_details_gt od,
2665 gl_budget_assignments ba,
2666 gl_bc_packets bp,
2667 gl_budorg_bc_options bo
2668 where (od.je_source_name || ';' || od.je_category_name =
2669 bp.je_source_name || ';' ||bp.je_category_name )
2670 and od.packet_id = bp.packet_id
2671 and ba.ledger_id (+) = g_ledger_id
2672 and ba.currency_code (+) = bp.currency_code
2673 and ba.code_combination_id (+) = bp.code_combination_id
2674 and bo.range_id(+) = ba.range_id
2675 and bo.funding_budget_version_id
2676 in (select BV1.budget_version_id
2677 from gl_budget_versions bv1, gl_budgets b,
2678 gl_period_statuses ps
2679 where ba.ledger_id = g_ledger_id
2680 and ba.currency_code = bp.currency_code
2681 and ba.code_combination_id = bp.code_combination_id
2682 and b.budget_name = bv1.budget_name
2683 and ((b.budget_type = 'payment'
2684 and bp.actual_flag in ('P', 'F'))
2685 or
2686 (b.budget_type = 'standard'
2687 and bp.actual_flag not in ('P', 'F')))
2688 and ps.application_id = 101
2689 and ps.ledger_id = g_ledger_id
2690 and ps.period_name = bp.period_name
2691 and ps.start_date
2692 >= (select p1.start_date
2693 from gl_period_statuses p1
2694 where p1.period_name = b.first_valid_period_name
2695 and p1.application_id = ps.application_id
2696 and p1.ledger_id = ps.ledger_id)
2697 and ps.end_date
2698 <= (select p2.end_date
2699 from gl_period_statuses p2
2700 where p2.period_name = b.last_valid_period_name
2701 and p2.application_id = ps.application_id
2702 and p2.ledger_id = ps.ledger_id))
2703 and bp.packet_id = g_packet_id_ursvd
2704 and bp.template_id is null
2705 and bp.status_code = 'A';
2706
2707 -- =========================== FND LOG ===========================
2708 psa_utils.debug_other_string(g_state_level,l_full_path, ' Insert gl_bc_packets -> ' || SQL%ROWCOUNT );
2709 -- ========================= FND LOG =============================
2710
2711 BEGIN
2712
2713 SELECT
2714 'There are USSGL rows in the packet'
2715 INTO
2716 l_dummy
2717 FROM
2718 DUAL
2719 WHERE EXISTS
2720 (
2721 SELECT
2722 'Record with non-null USSGL transaction code'
2723 FROM
2724 GL_BC_PACKETS BP
2725 WHERE
2726 BP.packet_id = g_packet_id_ursvd
2727 AND BP.ussgl_transaction_code IS NOT NULL
2728 );
2729
2730 g_append_je_flag := TRUE;
2731
2732 -- =========================== FND LOG ===========================
2733 psa_utils.debug_other_string(g_state_level,l_full_path, ' l_dummy -> ' || l_dummy );
2734 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_append_je_flag -> TRUE');
2735 -- ========================= FND LOG =============================
2736
2737 EXCEPTION
2738 WHEN OTHERS THEN
2739
2740 -- =========================== FND LOG ===========================
2741 psa_utils.debug_other_string(g_excep_level,l_full_path, ' g_append_je_flag -> FALSE');
2742 -- ========================= FND LOG =============================
2743
2744 g_append_je_flag := FALSE;
2745 END;
2746
2747 -- =========================== FND LOG ===========================
2748 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN -> TRUE ' );
2749 -- ========================= FND LOG =============================
2750
2751 return(TRUE);
2752
2753 EXCEPTION
2754
2755 WHEN OTHERS THEN
2756 -- =========================== FND LOG ===========================
2757 psa_utils.debug_other_string(g_excep_level,l_full_path, ' EXCEPTION WHEN OTHERS - ' || SQLERRM );
2758 -- ========================= FND LOG =============================
2759
2760 if pkt_id%ISOPEN then
2761 close pkt_id;
2762 end if;
2763
2764 message_token('PROCEDURE', 'Funds Checker');
2765 message_token('EVENT', SQLERRM);
2766 add_message('SQLGL', 'GL_UNHANDLED_EXCEPTION');
2767
2768 -- =========================== FND LOG ===========================
2769 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN -> FALSE');
2770 -- ========================= FND LOG =============================
2771
2772 g_debug := g_debug||'GLXFIU Failed : '||SQLERRM;
2773
2774 return(FALSE);
2775
2776 END glxfiu;
2777
2778 /* ============================= GLXFSS ============================== */
2779
2780 -- Setup and Summarization
2781
2782 -- This Module sets up the denormalized columns in the queue such as
2783 -- Budgetary Control Options, Funds Check Level, Account Type, Transaction
2784 -- effect on Funds Available, etc. It also validates the Accounting
2785 -- Flexfield and Period info, inserts Summary Transactions into the queue
2786 -- and also inserts the arrival sequence of the packet
2787
2788 FUNCTION glxfss RETURN BOOLEAN IS
2789
2790 sql_bcp VARCHAR2(5000);
2791 str_bc_option_id VARCHAR2(128);
2792
2793 cursor arrseq is
2794 select gl_bc_packet_arrival_order_s.nextval
2795 from dual;
2796
2797 cursor lock_gl_conc_ctrl is
2798 select 'Obtain Row Share Lock on the corresponding record for this Set of Books'
2799 from gl_concurrency_control ct
2800 where ct.concurrency_class = 'INSERT_PACKET_ARRIVAL'
2801 and ct.concurrency_entity_name = 'SET_OF_BOOKS'
2802 and ct.concurrency_entity_id = to_char(g_ledger_id)
2803 FOR UPDATE;
2804
2805 l_dummy varchar2(100);
2806
2807 OVERLAPPING_BUDGET EXCEPTION;
2808 PRAGMA EXCEPTION_INIT(OVERLAPPING_BUDGET,-1427);
2809
2810
2811 -- ========================= FND LOG ===========================
2812 l_full_path VARCHAR2(100);
2813 -- ========================= FND LOG ===========================
2814 BEGIN
2815
2816 l_full_path := g_path || 'glxfss.';
2817
2818 -- =========================== FND LOG ===========================
2819 psa_utils.debug_other_string(g_state_level,l_full_path, ' GLXFSS - START' );
2820 -- ========================= FND LOG =============================
2821
2822 -- Denormalized Columns are not updated if mode is Unreservation since
2823 -- this is handled in glxfiu()
2824
2825 -- ========================= FND LOG =============================
2826 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_fcmode -> ' || g_fcmode);
2827 -- ========================= FND LOG =============================
2828
2829 if g_fcmode <> 'U' then
2830
2831 -- Update denormalized columns for all detail transactions in the packet
2832 -- and perform Accounting Flexfield and Period validation as required. In
2833 -- case of error, set the result code to one of the following values :
2834 --
2835 -- Code Explanation
2836 -- ---- ------------------------------------------------------
2837 -- F20 Accounting Flexfield does not exist
2838 -- F21 Accounting Flexfield is disabled or out-of-date
2839 -- F22 Accounting Flexfield does not allow detail posting
2840 -- F23 Accounting Flexfield does not allow detail budget
2841 -- posting
2842 -- F24 Accounting Period does not exist
2843 -- F25 Accounting Period is neither Open nor Future Enterable
2844 -- F26 Accounting Period is not within an Open budget year
2845 -- F27 Budget is Frozen
2846 -- F28 USSGL Transaction Code is out-of-date
2847
2848
2849 begin
2850
2851 update gl_bc_packets bp
2852 set bp.funding_budget_version_id =
2853 (select decode(pk.actual_flag, 'B', pk.budget_version_id,
2854 bo.funding_budget_version_id)
2855 from gl_budget_assignments ba,
2856 gl_budgets b,
2857 gl_budget_versions bv,
2858 gl_period_statuses ps,
2859 gl_bc_packets pk,
2860 gl_budorg_bc_options bo
2861 where
2862 ba.ledger_id(+) = g_ledger_id
2863 and ba.currency_code(+) = decode(PK.currency_code,
2864 'STAT', 'STAT',
2865 g_func_curr_code)
2866 and ba.code_combination_id (+) = PK.code_combination_id
2867 and bo.range_id(+) = ba.range_id
2868 and bo.funding_budget_version_id = bv.budget_version_id
2869 and bv.budget_name = b.budget_name
2870 and ((b.budget_type = 'payment' and
2871 pk.actual_flag IN ('P', 'F'))
2872 or
2873 (b.budget_type = 'standard' and
2874 pk.actual_flag not in ('P', 'F')))
2875 and ps.application_id = 101
2876 and ps.ledger_id = g_ledger_id
2877 and ps.period_name = pk.period_name
2878 and ps.start_date >= (select p1.start_date
2879 from gl_period_statuses p1
2880 where p1.period_name = b.first_valid_period_name
2881 and p1.application_id = ps.application_id
2882 and p1.ledger_id = ps.ledger_id)
2883 and ps.end_date <= (select p2.end_date
2884 from gl_period_statuses p2
2885 where p2.period_name = b.last_valid_period_name
2886 and p2.application_id = ps.application_id
2887 and p2.ledger_id = ps.ledger_id)
2888 and pk.rowid = bp.rowid
2889 )
2890 where bp.packet_id = g_packet_id
2891 and bp.template_id is null
2892 and bp.funding_budget_version_id is null;
2893
2894 EXCEPTION
2895 WHEN OVERLAPPING_BUDGET THEN
2896
2897 -- =========================== FND LOG ===========================
2898 psa_utils.debug_other_string(g_state_level,l_full_path, ' There are multiple overlapping budgets assigned to account');
2899 psa_utils.debug_other_string(g_state_level,l_full_path, ' Update gl_bc_packets 1 updated failed');
2900 psa_utils.debug_other_string(g_state_level,l_full_path, ' Updating the status code = F/R based on g_fcmode');
2901 psa_utils.debug_other_string(g_state_level,l_full_path, ' Updating the result code= F77/F80 based on overlapping budget');
2902 -- ========================= FND LOG =============================
2903
2904 update gl_bc_packets bp
2905 set STATUS_CODE = DECODE(g_fcmode,'C','F','R'),
2906 RESULT_CODE=
2907 ( select DECODE(count(bo.FUNDING_BUDGET_VERSION_ID),1,'F77','F80')
2908 from
2909 gl_bc_packets pk,
2910 gl_budget_assignments ba,
2911 gl_budorg_bc_options bo
2912 where
2913 pk.rowid=bp.rowid
2914 and pk.code_combination_id=ba.code_combination_id
2915 and pk.ledger_id = ba.ledger_id
2916 and pk.currency_code = ba.currency_code
2917 and ba.range_id = bo.range_id
2918 )
2919 where
2920 bp.packet_id = g_packet_id;
2921
2922 -- =========================== FND LOG ===========================
2923 psa_utils.debug_other_string(g_state_level,l_full_path, ' Set g_overlapping_budget = TRUE, Return -> TRUE');
2924 -- ========================= FND LOG =============================
2925 g_overlapping_budget:=TRUE;
2926 return(TRUE);
2927 end;
2928
2929
2930 -- =========================== FND LOG ===========================
2931 psa_utils.debug_other_string(g_state_level,l_full_path, ' Update gl_bc_packets 1 updated -> ' || SQL%ROWCOUNT || ' rows');
2932 -- ========================= FND LOG =============================
2933
2934 update gl_bc_packets bp
2935 set (bp.automatic_encumbrance_flag,
2936 bp.funds_check_level_code,
2937 bp.tolerance_percentage,
2938 bp.tolerance_amount,
2939 bp.override_amount,
2940 bp.account_type,
2941 bp.dr_cr_code,
2942 bp.account_category_code,
2943 bp.effect_on_funds_code,
2944 bp.result_code) =
2945 (
2946 select 'Y',
2947 decode(pk.funding_budget_version_id, NULL, 'N', NULL),
2948 od.tolerance_percentage,
2949 od.tolerance_amount,
2950 od.override_amount,
2951 cc.account_type,
2952 decode(cc.account_type, 'A', 'D', 'E', 'D', 'D', 'D', 'C'),
2953 decode(cc.account_type, 'D', 'B', 'C', 'B', 'P'),
2954 decode(
2955 decode(pk.actual_flag || cc.account_type,
2956 'BL', 'dec',
2957 'BO', 'dec',
2958 'BR', 'dec',
2959 'AA', 'dec',
2960 'AE', 'dec',
2961 'EA', 'dec',
2962 'EE', 'dec',
2963 'AC', 'dec',
2964 'BC', 'n/a',
2965 'BD', 'n/a',
2966 'EC', 'n/a',
2967 'ED', 'n/a',
2968 'inc'),
2969 'dec',
2970 decode(sign(nvl(pk.accounted_dr, 0)-
2971 nvl(pk.accounted_cr, 0)), 1, 'D', 'I'),
2972 'inc',
2973 decode(sign(nvl(pk.accounted_dr, 0)-
2974 nvl(pk.accounted_cr, 0)), -1, 'D', 'I'),
2975 'n/a', 'I'),
2976 decode(cc.code_combination_id, null, 'F20',
2977 decode(cc.enabled_flag, 'N', 'F21',
2978 decode(pk.actual_flag ||
2979 cc.detail_posting_allowed_flag,
2980 'AN', 'F22', 'EN', 'F22',
2981 decode(pk.actual_flag ||
2982 cc.detail_budgeting_allowed_flag,
2983 'BN', 'F23',
2984 decode(ps.period_name, null, 'F24',
2985 decode(pk.actual_flag || ps.closing_status,
2986 'AN', 'F25', 'AC', 'F25', 'AP', 'F25',
2987 decode(pk.actual_flag ||
2988 nvl(br.open_flag, 'N'), 'BN', 'F26',
2989 decode(pk.actual_flag || bv.status,
2990 'BF', 'F27',
2991 decode(sign(nvl(pk.bc_date, sysdate) -
2992 nvl(uc.start_date_active, nvl(pk.bc_date, sysdate))),
2993 -1, 'F28',
2994 decode(sign(nvl(uc.end_date_active,
2995 nvl(pk.bc_date, sysdate)) - nvl(pk.bc_date, sysdate)), -1, 'F28',
2996 decode(substr(pk.result_code,1,1),
2997 'X', 'F' || substr(pk.result_code,2),
2998 null)))))))))))
2999 from gl_ussgl_transaction_codes uc,
3000 gl_budget_versions bv,
3001 gl_budget_period_ranges br,
3002 gl_period_statuses ps,
3003 gl_code_combinations cc,
3004 psa_option_details_gt od,
3005 gl_bc_packets pk
3006 where uc.chart_of_accounts_id (+) = g_coa_id
3007 and uc.ussgl_transaction_code (+) =
3008 nvl(pk.ussgl_transaction_code, -1)
3009 and bv.budget_version_id (+) = nvl(pk.budget_version_id, -1)
3010 and br.budget_version_id (+) = nvl(pk.budget_version_id, -1)
3011 and br.period_year (+) = pk.period_year
3012 and pk.period_num between br.start_period_num (+)
3013 and br.end_period_num (+)
3014 and ps.application_id (+) = 101
3015 and ps.ledger_id (+) = g_ledger_id
3016 and ps.period_name (+) = pk.period_name
3017 and cc.code_combination_id (+) = pk.code_combination_id
3018 and (od.je_source_name || ';' || od.je_category_name =
3019 pk.je_source_name || ';' || pk.je_category_name )
3020 and od.packet_id = pk.packet_id
3021 and pk.rowid = bp.rowid
3022 )
3023 where bp.packet_id = g_packet_id
3024 and bp.template_id is null;
3025
3026 -- =========================== FND LOG ===========================
3027 psa_utils.debug_other_string(g_state_level,l_full_path, ' Update gl_bc_packets 2 updated -> ' || SQL%ROWCOUNT || ' rows');
3028 -- ========================= FND LOG =============================
3029
3030 update gl_bc_packets bp
3031 set (funds_check_level_code,
3032 amount_type,
3033 boundary_code) = (select
3034 nvl(min(decode(bo.funds_check_level_code, 'D',
3035 nvl(od.funds_check_level_code, 'D'),
3036 nvl(bo.funds_check_level_code, 'N'))), 'N'),
3037 min(bo.amount_type),
3038 min(bo.boundary_code)
3039 from gl_bc_packets pk,
3040 psa_option_details_gt od,
3041 gl_budget_assignments ba,
3042 gl_budorg_bc_options bo
3043 where pk.rowid = bp.rowid
3044 and (od.je_source_name || ';' || od.je_category_name =
3045 pk.je_source_name || ';' || pk.je_category_name )
3046 and od.packet_id = pk.packet_id
3047 and ba.ledger_id = g_ledger_id
3048 and ba.currency_code = decode(pk.currency_code,
3049 'STAT', 'STAT',
3050 g_func_curr_code)
3051 and ba.code_combination_id = pk.code_combination_id
3052 and bo.range_id = ba.range_id
3053 and bo.funding_budget_version_id = pk.funding_budget_version_id)
3054 where bp.packet_id = g_packet_id
3055 and bp.funding_budget_version_id is not null;
3056
3057
3058 -- =========================== FND LOG ===========================
3059 psa_utils.debug_other_string(g_state_level,l_full_path, ' Update gl_bc_packets 3 updated -> ' || SQL%ROWCOUNT || ' rows');
3060 -- ========================= FND LOG =============================
3061
3062
3063 /*----------------------------------------------------------------------+
3064 | Bug 5242198 : When an account is assigned with different funds check |
3065 | level(say Absolute and Advisory) the account is assumed to have a |
3066 | funds check level of absolute with no funding budget for preiods with|
3067 | no budget assignments... |
3068 +----------------------------------------------------------------------*/
3069
3070 if(nvl(g_enable_efc_flag,'N')='Y') THEN
3071 update gl_bc_packets bp
3072 set bp.funds_check_level_code = 'B'
3073 where bp.packet_id = g_packet_id
3074 and bp.template_id is null
3075 and bp.funds_check_level_code = 'N'
3076 and bp.funding_budget_version_id IS NULL
3077 and exists
3078 (select null
3079 from gl_budget_assignments ba
3080 where ba.code_combination_id = bp.code_combination_id
3081 and ba.ledger_id = bp.ledger_id
3082 and ba.currency_code = bp.currency_code
3083
3084 );
3085 end if;
3086 end if; -- g_fcmode <> 'U'
3087
3088
3089 -- Prior to inserting Summary Transactions for the packet, we lock the
3090 -- dummy table gl_bc_dual2 in row share mode to ensure data consistency
3091 -- between the Funds Checker Summarization and the Add/Delete Summary
3092 -- Accounts process. This ensures that that only one process will
3093 -- summarize the transactions in the queue
3094
3095 -- When a lock on gl_bc_dual2 is not available then
3096 --
3097 -- if Funds Checker is invoked from a Concurrent Process, it waits
3098 --
3099 -- if Funds Checker is invoked from an Online Process, it exits with
3100 -- a fatal error
3101
3102
3103 if g_conc_flag then
3104 -- =========================== FND LOG ===========================
3105 psa_utils.debug_other_string(g_state_level,l_full_path,
3106 ' Lock gl_bc_dual2 in row share mode' );
3107 -- ========================= FND LOG =============================
3108 LOCK TABLE gl_bc_dual2 IN ROW SHARE MODE;
3109 else
3110 -- =========================== FND LOG ===========================
3111 psa_utils.debug_other_string(g_state_level,l_full_path,
3112 ' Lock gl_bc_dual2 in row share mode nowait' );
3113 -- ========================= FND LOG =============================
3114 LOCK TABLE gl_bc_dual2 IN ROW SHARE MODE NOWAIT;
3115 end if;
3116
3117
3118 -- Insert Summary Transactions for the Packet. Summarization Grouping is
3119 -- based on Summary Code Combination, Balance Type, Period Name, Currency
3120 -- Code, Encumbrance Type, JE Source, JE Category and Budget Name
3121
3122 -- The Join Condition
3123 --
3124 -- st.account_category_code = bp.account_category_code
3125 --
3126 -- ensures that if a template is Proprietary, Summarization ignore any
3127 -- Budgetary Detail Accounts that may fall into the same Rollup Structure,
3128 -- and vice-versa
3129
3130 insert into gl_bc_packets (packet_id,
3131 ledger_id,
3132 je_source_name,
3133 je_category_name,
3134 code_combination_id,
3135 actual_flag,
3136 period_name,
3137 period_year,
3138 period_num,
3139 quarter_num,
3140 currency_code,
3141 status_code,
3142 last_update_date,
3143 last_updated_by,
3144 budget_version_id,
3145 encumbrance_type_id,
3146 template_id,
3147 entered_dr,
3148 entered_cr,
3149 accounted_dr,
3150 accounted_cr,
3151 funding_budget_version_id,
3152 funds_check_level_code,
3153 amount_type,
3154 boundary_code,
3155 tolerance_percentage,
3156 tolerance_amount,
3157 override_amount,
3158 dr_cr_code,
3159 account_category_code,
3160 effect_on_funds_code,
3161 session_id,
3162 serial_id,
3163 application_id)
3164 select
3165 min(bp.packet_id),
3166 min(bp.ledger_id),
3167 min(bp.je_source_name),
3168 min(bp.je_category_name),
3169 min(ah.summary_code_combination_id),
3170 min(bp.actual_flag),
3171 min(bp.period_name),
3172 min(bp.period_year),
3173 min(bp.period_num),
3174 min(bp.quarter_num),
3175 min(bp.currency_code),
3176 min(bp.status_code),
3177 min(bp.last_update_date),
3178 min(bp.last_updated_by),
3179 min(decode(bp.actual_flag, 'B', bp.budget_version_id, null)),
3180 min(decode(bp.actual_flag, 'E', bp.encumbrance_type_id,null)),
3181 min(st.template_id),
3182 sum(nvl(bp.entered_dr, 0)),
3183 sum(nvl(bp.entered_cr, 0)),
3184 sum(nvl(bp.accounted_dr, 0)),
3185 sum(nvl(bp.accounted_cr, 0)),
3186 min(sb.funding_budget_version_id),
3187 min(decode(sb.funds_check_level_code, 'D',
3188 nvl(od.funds_check_level_code, 'D'),
3189 sb.funds_check_level_code)),
3190 min(sb.amount_type),
3191 min(sb.boundary_code),
3192 min(od.tolerance_percentage),
3193 min(od.tolerance_amount),
3194 min(od.override_amount),
3195 min(sb.dr_cr_code),
3196 min(st.account_category_code),
3197 decode(
3198 decode(min(bp.actual_flag) || min(sb.dr_cr_code) ||
3199 min(st.account_category_code),
3200 'BCP', 'dec', 'ADP', 'dec',
3201 'EDP', 'dec', 'ACB', 'dec', 'BCB',
3202 'n/a', 'BDB', 'n/a',
3203 'ECB', 'n/a', 'EDB', 'n/a', 'inc'),
3204 'dec',
3205 decode(sign(sum(nvl(bp.accounted_dr, 0) -
3206 nvl(bp.accounted_cr, 0))), 1, 'D', 'I'),
3207 'inc',
3208 decode(sign(sum(nvl(bp.accounted_dr, 0) -
3209 nvl(bp.accounted_cr, 0))), -1, 'D', 'I'),
3210 'n/a', 'I'),
3211 min(bp.session_id),
3212 min(bp.serial_id),
3213 min(bp.application_id)
3214 from psa_option_details_gt od,
3215 gl_period_statuses ps,
3216 gl_summary_templates st,
3217 gl_account_hierarchies ah,
3218 gl_bc_packets bp,
3219 gl_summary_bc_options sb,
3220 gl_budgets b,
3221 gl_budget_versions bv,
3222 gl_period_statuses ps2
3223 where st.status = 'F'
3224 and sb.funds_check_level_code || od.funds_check_level_code <> 'DN'
3225 and st.template_id = ah.template_id
3226 and sb.funding_budget_version_id = decode(bp.actual_flag,
3227 'B', bp.budget_version_id,
3228 sb.funding_budget_version_id)
3229 and st.account_category_code = bp.account_category_code
3230 and ps.ledger_id = g_ledger_id
3231 and ps.application_id = 101
3232 and ps.period_name = st.start_actuals_period_name
3233 and (ps.period_year * 10000 + ps.period_num) <=
3234 (bp.period_year * 10000 + bp.period_num)
3235 AND SB.template_id = ST.template_id
3236 AND SB.funding_budget_version_id = BV.budget_version_id
3237 AND BV.budget_name = B.budget_name
3238 AND ((BV.budget_type = 'payment' AND BP.actual_flag in ('P', 'F'))
3239 OR (BV.budget_type = 'standard' AND BP.actual_flag in ('A', 'E'))
3240 OR (BP.actual_flag = 'B'))
3241 and ps2.ledger_id = g_ledger_id
3242 and ps2.application_id = 101
3243 AND PS2.period_name = BP.period_name
3244 AND PS2.start_date >= (select P1.start_date
3245 from GL_PERIOD_STATUSES P1
3246 where P1.application_id = ps2.application_id
3247 and P1.ledger_id = ps2.ledger_id
3248 and P1.period_name = B.first_valid_period_name)
3249 AND PS2.end_date <= (select P2.end_date
3250 from GL_PERIOD_STATUSES P2
3251 where P2.application_id = ps2.application_id
3252 and P2.ledger_id = ps2.ledger_id
3253 and P2.period_name = B.last_valid_period_name)
3254 and ah.ledger_id = g_ledger_id
3255 and ah.detail_code_combination_id = bp.code_combination_id
3256 and od.packet_id = bp.packet_id
3257 and od.je_source_name || ';' || od.je_category_name =
3258 bp.je_source_name || ';' || bp.je_category_name
3259 and (bp.je_batch_id is not null
3260 or bp.automatic_encumbrance_flag = 'Y'
3261 or bp.actual_flag <> 'E')
3262 and bp.packet_id = g_packet_id
3263 and bp.result_code is null
3264 group by ah.summary_code_combination_id,
3265 bp.actual_flag,
3266 bp.period_name,
3267 bp.encumbrance_type_id,
3268 bp.period_num, -- Bug 3259452
3269 bp.currency_code,
3270 bp.je_source_name,
3271 bp.je_category_name,
3272 bp.budget_version_id
3273 having sum(nvl(bp.accounted_dr, 0) - nvl(bp.accounted_cr, 0)) <> 0;
3274
3275
3276
3277 -- Set Summarized Flag if Summary Transactions were inserted into the queue
3278
3279 if SQL%FOUND then
3280 -- =========================== FND LOG ===========================
3281 psa_utils.debug_other_string(g_state_level,l_full_path,
3282 ' Insert gl_bc_packets - summ trans ' || SQL%ROWCOUNT );
3283
3284 psa_utils.debug_other_string(g_state_level,l_full_path,
3285 ' g_summarized_flag -> TRUE' );
3286 -- ========================= FND LOG =============================
3287 g_summarized_flag := TRUE;
3288 end if;
3289
3290
3291 -- Insert Arrival Sequence for the Packet. The Row Share Lock ensures that
3292 -- packets are assigned sequences strictly in order of arrival
3293
3294 -- When a lock on gl_concurrency_control is not available then
3295 --
3296 -- if Funds Checker is invoked from a Concurrent Process, it waits
3297 --
3298 -- if Funds Checker is invoked from an Online Process, it exits with
3299 -- an error
3300
3301 if g_conc_flag then
3302 -- =========================== FND LOG ===========================
3303 psa_utils.debug_other_string(g_state_level,l_full_path,
3304 ' g_conc_flag -> TRUE' );
3305 -- ========================= FND LOG =============================
3306
3307 open lock_gl_conc_ctrl;
3308 fetch lock_gl_conc_ctrl into l_dummy;
3309 close lock_gl_conc_ctrl;
3310
3311 end if;
3312
3313
3314 -- Get Arrival Sequence
3315
3316 open arrseq;
3317 fetch arrseq into g_arrival_seq;
3318 close arrseq;
3319
3320 -- =========================== FND LOG ===========================
3321 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_arrival_seq -> ' || g_arrival_seq);
3322 -- ========================= FND LOG =============================
3323
3324 insert into gl_bc_packet_arrival_order
3325 (packet_id,
3326 ledger_id,
3327 arrival_seq,
3328 affect_funds_flag,
3329 last_update_date,
3330 last_updated_by)
3331 values (g_packet_id,
3332 g_ledger_id,
3333 g_arrival_seq,
3334 decode(g_fcmode, 'C', 'N', 'Y'),
3335 sysdate,
3336 g_user_id);
3337
3338
3339 -- =========================== FND LOG ===========================
3340 psa_utils.debug_other_string(g_state_level,l_full_path,
3341 ' insert gl_bc_packet_arrival_order -> ' || SQL%ROWCOUNT);
3342 -- ========================= FND LOG =============================
3343
3344 -- Commit to release Lock on gl_concurrency_control
3345 commit;
3346
3347
3348 -- Since the previous Commit has also released the lock on gl_bc_dual2, we
3349 -- need to reestablish the lock to maintain data consistency between the
3350 -- Funds Checker Summarization and the Add/Delete Summary Accounts
3351 -- process
3352
3353 -- =========================== FND LOG ===========================
3354 psa_utils.debug_other_string(g_state_level,l_full_path,
3355 ' lock table gl_bc_dual2 in row share mode nowait');
3356 -- ========================= FND LOG =============================
3357
3358 LOCK TABLE gl_bc_dual2 IN ROW SHARE MODE NOWAIT;
3359
3360 -- =========================== FND LOG ===========================
3361 psa_utils.debug_other_string(g_state_level,l_full_path,
3362 ' RETURN -> TRUE ');
3363 -- ========================= FND LOG =============================
3364
3365 return(TRUE);
3366
3367 EXCEPTION
3368
3369 WHEN OTHERS THEN
3370
3371 -- =========================== FND LOG ===========================
3372 psa_utils.debug_other_string(g_excep_level,l_full_path, ' EXCEPTION WHEN OTHERS ' || SQLERRM);
3373 -- ========================= FND LOG =============================
3374
3375 if arrseq%ISOPEN then
3376 close arrseq;
3377 end if;
3378
3379 if SQLCODE = -54 then
3380 message_token('PROCEDURE', 'Funds Checker');
3381 message_token('EVENT', 'Table Locked by Add/Delete Summary Accounts Process');
3382 add_message('SQLGL', 'GL_UNHANDLED_EXCEPTION');
3383 else
3384 message_token('PROCEDURE', 'Funds Checker');
3385 message_token('EVENT', SQLERRM);
3386 add_message('SQLGL', 'GL_UNHANDLED_EXCEPTION');
3387 end if;
3388
3389 -- =========================== FND LOG ===========================
3390 psa_utils.debug_other_string(g_excep_level,l_full_path, ' RETURN -> FALSE');
3391 -- ========================= FND LOG =============================
3392 g_debug := g_debug||'GLXFSS Failed : '||SQLERRM;
3393
3394 return(FALSE);
3395
3396 END glxfss;
3397
3398 /* ============================= GLXFGB =========================== */
3399
3400 -- Process Balances
3401 -- Find Pending and Approved Actual, Budget and Encumbrance transaction
3402 -- balances in the queue that would affect funds availability for the
3403 -- transactions in this packet
3404 -- Find the posted actual, budget and encumbrance balances in the balances
3405 -- table that would affect funds availability for the transactions in this
3406 -- packet
3407
3408 FUNCTION glxfgb RETURN BOOLEAN IS
3409
3410 -- Bug 3574935
3411
3412 --Bug 6823089 ..
3413 --l_max_packet_id gl_bc_packets.packet_id%type;
3414
3415 -- Bug 5644702
3416 l_effective_period_num gl_period_statuses.effective_period_num%TYPE;
3417 l_period_name gl_period_statuses.period_name%TYPE;
3418 l_quarter_num gl_period_statuses.quarter_num%TYPE;
3419 l_period_year gl_period_statuses.period_year%TYPE;
3420
3421 -- ========================= FND LOG ===========================
3422 l_full_path VARCHAR2(100);
3423 -- ========================= FND LOG ===========================
3424 BEGIN
3425
3426 l_full_path := g_path || 'glxfgb';
3427
3428 -- =========================== FND LOG ===========================
3429 psa_utils.debug_other_string(g_state_level,l_full_path, ' GLXFGB - START' );
3430 -- ========================= FND LOG =============================
3431
3432
3433 -- Bug 3574935 .. Start
3434 -- Obtain the maximum packet_id less than the current arrival sequence from
3435 -- table gl_bc_packet_arrival_order. This will then be used in the following
3436 -- UPDATE statement to help improve performance of the query. Making use of
3437 -- packet_id condition in the subquery makes index gl_bc_packets_n2 more
3438 -- selective and reduces number of rows processed during access to the table
3439 -- gl_bc_packet_arrival_order
3440
3441 -- Bug 4651919 .. Start
3442 -- Added ledger_id and affect_funds_flag conditions in WHERE clause
3443
3444 -- Bug 6823089.
3445 -- SELECT max(packet_id) INTO l_max_packet_id
3446 -- FROM gl_bc_packet_arrival_order
3447 -- WHERE arrival_seq < g_arrival_seq
3448 -- AND ledger_id = g_ledger_id;
3449 -- AND affect_funds_flag = 'Y';
3450
3451 -- Bug 4651919 .. End
3452
3453 -- Bug 3574935 .. End
3454
3455 -- =========================== FND LOG ===========================
3456 -- psa_utils.debug_other_string(g_state_level,l_full_path, ' l_max_packet_id -> '|| l_max_packet_id );
3457 -- ========================= FND LOG =============================
3458
3459 -- Lock dummy table gl_bc_dual in Row Share Mode to ensure Read Consistency
3460 -- between gl_bc_packets and gl_balances in the next two balance update
3461 -- SQLs. This scheme requires posting to lock gl_bc_dual in exclusive mode
3462 -- before it commits, and to wait in a sleep cycle of 15 seconds until all
3463 -- the Funds Check processes release the locks. This prevents the Funds
3464 -- Checker from counting the Balances twice, in case Posting Commits in
3465 -- between the two SQLs, and some of the pending balances got transferred
3466 -- to gl_balances, where the funds checker would mistakenly treat them as
3467 -- Posted Balances in the second SQL
3468
3469 -- When a lock on gl_bc_dual is not available then
3470 --
3471 -- if Funds Checker is invoked from a Concurrent Process, it waits
3472 --
3473 -- if Funds Checker is invoked from an Online Process, it exits with
3474 -- a fatal error
3475
3476 if g_conc_flag then
3477 -- =========================== FND LOG ===========================
3478 psa_utils.debug_other_string(g_state_level,l_full_path,
3479 ' Lock table gl_bc_dual in row share mode' );
3480 -- ========================= FND LOG =============================
3481 LOCK TABLE gl_bc_dual IN ROW SHARE MODE;
3482 else
3483 -- =========================== FND LOG ===========================
3484 psa_utils.debug_other_string(g_state_level,l_full_path,
3485 ' Lock table gl_bc_dual in row share mode NOWAIT' );
3486 -- ========================= FND LOG =============================
3487 LOCK TABLE gl_bc_dual IN ROW SHARE MODE NOWAIT;
3488 end if;
3489
3490
3491 -- Update Approved and Pending Balances in gl_bc_packets
3492 --
3493 -- Transactions in the gl_bc_packets that would affect the transactions in
3494 -- this packet are :
3495 --
3496 -- all approved packets, for the same Set of Books, that arrived earlier
3497 --
3498 -- all pending packets, for the same Set of Books, that arrived earlier
3499 -- and which reduce Funds Available
3500 --
3501 -- all rows in the current packet that have a lower combined score of
3502 -- Rank(Funds Check Level) || Rowid than the row currently being
3503 -- processed
3504 --
3505 -- all transactions in the current packet that would increase funds
3506 -- available
3507
3508 -- Summary of Funds Check Level Rank :
3509 --
3510 -- Funds Check Level Rank
3511 -- ----------------- ----
3512 -- None (N) 0
3513 -- Advisory (D) 1
3514 -- Absolute (B) 2
3515 --
3516 -- For example, when processing an Advisory Transaction, rows in the same
3517 -- packet that need to be considered in this category include all rows
3518 -- with Funds Check Level None, and all Advisory Transactions with a
3519 -- lower rowid than that of the row currently being processed
3520
3521 -- Subquery needs to join to gl_budgets, gl_budget_versions and
3522 -- gl_period_statuses to get the last period in the latest open year of
3523 -- the Funding Budget for the Boundary Code 'project'
3524
3525 -- Summary of WHERE clauses based on Amount Type and Boundary :
3526 --
3527 -- Amount Type Where Clauses
3528 -- ----------- -------------
3529 -- PTD where p2.period_year = p1.period_year
3530 -- and p2.period_num = p1.period_num
3531 --
3532 -- QTD where p2.period_year = p1.period_year
3533 -- and p2.quarter_num = p1.quarter_num
3534 --
3535 -- YTD where p2.period_year = p1.period_year
3536 --
3537 -- PJTD <no restriction>
3538 --
3539 -- Boundary Where Clauses
3540 -- -------- -------------
3541 -- Period and ((p2.period_year = p1.period_year
3542 -- and p2.period_num <= p1.period_num)
3543 -- or (p2.period_year < p1.period_year))
3544 --
3545 -- Quarter and ((p2.period_year = p1.period_year
3546 -- and p2.quarter_num <= p1.quarter_num)
3547 -- or (p2.period_year < p1.period_year))
3548 --
3549 -- Year and p2.period_year <= p1.period_year
3550 --
3551 -- Project and ((p2.period_year = EOB.period_year
3552 -- and p2.period_num <= EOB.period_num)
3553 -- or (p2.period_year < EOB.period_year))
3554 -- EOB = Last Period in Latest Open Year of Budget
3555
3556
3557 update
3558 gl_bc_packets bp
3559 set (bp.budget_approved_balance,
3560 bp.actual_approved_balance,
3561 bp.encumbrance_approved_balance,
3562 bp.budget_pending_balance,
3563 bp.actual_pending_balance,
3564 bp.encumbrance_pending_balance) =
3565 (
3566 select
3567 sum(decode(pk.status_code || pk.actual_flag,
3568 'AB', nvl(pk.accounted_dr, 0) - nvl(pk.accounted_cr, 0),
3569 0)
3570 ),
3571 sum(decode(pk.status_code || pk.actual_flag,
3572 'AA', nvl(pk.accounted_dr, 0) - nvl(pk.accounted_cr, 0),
3573 0)
3574 ),
3575 sum(decode(pk.status_code || pk.actual_flag,
3576 'AE', nvl(pk.accounted_dr, 0) - nvl(pk.accounted_cr, 0),
3577 0)
3578 ),
3579 sum(decode(pk.status_code || pk.actual_flag,
3580 'PB', nvl(pk.accounted_dr, 0) - nvl(pk.accounted_cr, 0),
3581 'CB', nvl(pk.accounted_dr, 0) - nvl(pk.accounted_cr, 0),
3582 0)
3583 ),
3584 sum(decode(pk.status_code || pk.actual_flag,
3585 'PA', nvl(pk.accounted_dr, 0) - nvl(pk.accounted_cr, 0),
3586 'CA', nvl(pk.accounted_dr, 0) - nvl(pk.accounted_cr, 0),
3587 0)
3588 ),
3589 sum(decode(pk.status_code || pk.actual_flag,
3590 'PE', nvl(pk.accounted_dr, 0) - nvl(pk.accounted_cr, 0),
3591 'CE', nvl(pk.accounted_dr, 0) - nvl(pk.accounted_cr, 0),
3592 0)
3593 )
3594 from gl_period_statuses ps,
3595 gl_budgets bd,
3596 gl_budget_versions bv,
3597 gl_bc_packets pk,
3598 gl_bc_packet_arrival_order ao
3599 where ps.application_id = 101
3600 and ps.ledger_id = g_ledger_id
3601 and ps.period_name = bd.last_valid_period_name
3602 and bd.budget_name = bv.budget_name
3603 and bd.budget_type = bv.budget_type
3604 and bv.budget_version_id = bp.funding_budget_version_id
3605 and pk.funding_budget_version_id = bp.funding_budget_version_id
3606 and pk.ledger_id = g_ledger_id
3607 and pk.code_combination_id = bp.code_combination_id
3608 and (pk.budget_version_id is null
3609 or pk.budget_version_id = bp.funding_budget_version_id)
3610 and pk.period_year = decode(bp.amount_type, 'PJTD',
3611 pk.period_year, bp.period_year)
3612 and pk.period_num = decode(bp.amount_type, 'PTD',
3613 bp.period_num, pk.period_num)
3614 and pk.quarter_num = decode(bp.amount_type, 'QTD',
3615 bp.quarter_num, pk.quarter_num)
3616 and ((pk.period_year = decode(bp.boundary_code,
3617 'J', bd.latest_opened_year,
3618 bp.period_year)
3619 and pk.period_num <= decode(bp.boundary_code, 'P',
3620 bp.period_num, 'J',
3621 decode(ps.period_year,
3622 bd.latest_opened_year,
3623 ps.period_num,
3624 pk.period_num), pk.period_num)
3625 and pk.quarter_num <= decode(bp.boundary_code, 'Q',
3626 bp.quarter_num, pk.quarter_num))
3627 or pk.period_year < decode(bp.boundary_code, 'J',
3628 bd.latest_opened_year,
3629 bp.period_year))
3630 and pk.currency_code = decode(pk.actual_flag, 'B',
3631 g_func_curr_code, pk.currency_code)
3632 and pk.packet_id = ao.packet_id
3633 and ((pk.packet_id = g_packet_id -- Bug 3574935
3634 and (decode(pk.funds_check_level_code, 'N', '0', 'D', '1',
3635 'B', '2') || pk.rowid <
3636 decode(bp.funds_check_level_code, 'N', '0', 'D', '1',
3637 'B', '2') || bp.rowid
3638 or pk.effect_on_funds_code = 'I'))
3639
3640 --Bug 6823089.. Start
3641 -- or (pk.packet_id <= l_max_packet_id -- Bug 3574935, Bug 4119217
3642 or (pk.packet_id >= 0
3643 --Bug 6823089.. End
3644
3645 and ao.arrival_seq < g_arrival_seq
3646 -- and ao.affect_funds_flag = 'Y'
3647 and ao.ledger_id = g_ledger_id
3648 and nvl(pk.result_code, 'X') like
3649 decode(pk.status_code, 'A', 'P%', 'P', 'P%', 'C', 'P%', 'X') -- Bug 4630687
3650 -- Bug 5046369 start
3651 and (
3652 (pk.status_code IN ('P', 'C')
3653 and exists (select 'Packet is valid for the current session'
3654 from v$session s
3655 WHERE s.audsid = pk.session_id
3656 AND s.serial# = pk.serial_id)
3657 )
3658 OR
3659 pk.status_code = 'A'
3660 )))
3661 -- rgopalan Bug 2799257
3662 and EXISTS
3663 (SELECT 'x' FROM fnd_currencies
3664 WHERE currency_code = PK.currency_code
3665 AND currency_flag = 'Y')
3666 )
3667 where bp.packet_id = g_packet_id
3668 and bp.result_code is null
3669 and bp.effect_on_funds_code = 'D'
3670 and bp.funds_check_level_code <> 'N'
3671 and bp.currency_code = decode(bp.actual_flag, 'B', g_func_curr_code,
3672 bp.currency_code)
3673 and bp.funding_budget_version_id = decode(bp.actual_flag, 'B',
3674 bp.budget_version_id,
3675 bp.funding_budget_version_id)
3676 -- rgopalan Bug 27992557
3677 and exists
3678 (SELECT 'x' FROM fnd_currencies
3679 WHERE currency_code = BP.currency_code
3680 AND currency_flag = 'Y');
3681
3682
3683 -- =========================== FND LOG ===========================
3684 psa_utils.debug_other_string(g_state_level,l_full_path,
3685 ' Update approved and pending balance in gl_bc_packets ' || SQL%ROWCOUNT );
3686 -- ========================= FND LOG =============================
3687
3688
3689 -- Update Posted Balances in gl_bc_packets
3690 --
3691 -- For Actuals, we subtract the begin balances of the first period of the
3692 -- transaction year, i.e YTD Funds Available includes actual activities
3693 -- accumulated during the current transaction year
3694 --
3695 -- For Budgets and Encumbrances, we do not need to include the begin
3696 -- balances of the first period since these are encumbrances, encumbered
3697 -- budgets and/or unused funds that are carried forward from the previous
3698 -- year
3699
3700 -- Subtraction of first period actual begin balance is done via special rows
3701 -- in gl_bc_period_map with boundary code 'S'. The PM.boundary_code AND
3702 -- clause in the correlated update query joins to these 'S' rows in addition
3703 -- to the regular PM rows for the case of YTD, and b/s or summary accounts,
3704 -- where they are eventually used in the 'AYTD' sum decode operation for the
3705 -- subtraction
3706 --
3707 -- Explain Plan :
3708 --
3709 -- OPERATION OPTIONS OBJECT_NAME
3710 -- ------------------------------------ ----------- -------------------
3711 -- SORT AGGREGATE
3712 -- NESTED LOOPS
3713 -- NESTED LOOPS
3714 -- TABLE ACCESS BY ROWID GL_BC_PACKETS
3715 -- INDEX RANGE SCAN GL_BC_PACKETS_N1
3716 -- INDEX RANGE SCAN GL_BC_PERIOD_MAP_U2
3717 -- TABLE ACCESS BY ROWID GL_BALANCES
3718 -- INDEX RANGE SCAN GL_BALANCES_N1
3719 --
3720
3721 -- Due to Bug 5644702 moved the fix of Bug 3243216 here.
3722
3723 BEGIN
3724 SELECT nvl(effective_period_num,0), period_name, NVL(quarter_num,0), NVL(period_year,0)
3725 INTO l_effective_period_num, l_period_name, l_quarter_num, l_period_year
3726 FROM gl_period_statuses
3727 WHERE ledger_id = g_ledger_id
3728 AND application_id = 101
3729 AND closing_status = 'O'
3730 AND effective_period_num =
3731 (SELECT max(effective_period_num)
3732 FROM gl_period_statuses
3733 WHERE ledger_id = g_ledger_id
3734 AND application_id = 101
3735 AND closing_status = 'O');
3736 EXCEPTION
3737 WHEN no_data_found THEN
3738 l_effective_period_num := 0;
3739 l_period_name := NULL;
3740 l_quarter_num := 0;
3741 l_period_year := 0;
3742 END;
3743 -- =========================== FND LOG ===========================
3744 psa_utils.debug_other_string(g_state_level,l_full_path,
3745 ' Picking up the lates OPEN period ' || SQL%ROWCOUNT );
3746 psa_utils.debug_other_string(g_state_level,l_full_path, ' l_effective_period_num -> ' || l_effective_period_num);
3747 psa_utils.debug_other_string(g_state_level,l_full_path, ' l_period_name -> ' || l_period_name);
3748 psa_utils.debug_other_string(g_state_level,l_full_path, ' l_quarter_num -> ' || l_quarter_num);
3749 psa_utils.debug_other_string(g_state_level,l_full_path, ' l_period_year -> ' || l_period_year);
3750 -- ========================= FND LOG =============================
3751
3752 -- Bugfix 2231059
3753
3754 update
3755 gl_bc_packets bp
3756 set (bp.budget_posted_balance,
3757 bp.actual_posted_balance,
3758 bp.encumbrance_posted_balance) =
3759 (
3760 select
3761
3762 sum(decode(gb.actual_flag || bp.amount_type, 'BPTD',
3763 nvl(gb.period_net_dr, 0) - nvl(gb.period_net_cr, 0),
3764 'BQTD', nvl(gb.quarter_to_date_dr, 0) -
3765 nvl(gb.quarter_to_date_cr, 0) +
3766 nvl(gb.period_net_dr, 0)- nvl(gb.period_net_cr, 0),
3767 'BYTD', nvl(gb.begin_balance_dr, 0) -
3768 nvl(gb.begin_balance_cr, 0) + nvl(gb.period_net_dr, 0) -
3769 nvl(gb.period_net_cr, 0),
3770 'BPJTD', nvl(gb.project_to_date_dr, 0) -
3771 nvl(gb.project_to_date_cr, 0) +
3772 nvl(gb.period_net_dr, 0) - nvl(gb.period_net_cr, 0), 0)),
3773 sum(decode(gb.actual_flag || bp.amount_type, 'APTD',
3774 nvl(gb.period_net_dr, 0) - nvl(gb.period_net_cr, 0),
3775 'AQTD', nvl(gb.quarter_to_date_dr, 0) -
3776 nvl(gb.quarter_to_date_cr, 0) +
3777 nvl(gb.period_net_dr, 0) - nvl(gb.period_net_cr, 0),
3778 'AYTD', decode(pm.boundary_code, 'S',
3779 nvl(gb.begin_balance_cr, 0) -
3780 nvl(gb.begin_balance_dr, 0),
3781 nvl(gb.begin_balance_dr, 0) -
3782 nvl(gb.begin_balance_cr, 0) + nvl(gb.period_net_dr, 0) -
3783 nvl(gb.period_net_cr, 0)),
3784 'APJTD', nvl(gb.project_to_date_dr, 0) -
3785 nvl(gb.project_to_date_cr, 0) +
3786 nvl(gb.period_net_dr, 0) - nvl(gb.period_net_cr, 0), 0)),
3787 sum(decode(gb.actual_flag || bp.amount_type, 'EPTD',
3788 nvl(gb.period_net_dr, 0) - nvl(gb.period_net_cr, 0),
3789 'EQTD', nvl(gb.quarter_to_date_dr, 0) -
3790 nvl(gb.quarter_to_date_cr, 0) +
3791 nvl(gb.period_net_dr, 0) - nvl(gb.period_net_cr, 0),
3792 'EYTD', nvl(gb.begin_balance_dr, 0) -
3793 nvl(gb.begin_balance_cr, 0) + nvl(gb.period_net_dr, 0) -
3794 nvl(gb.period_net_cr, 0),
3795 'EPJTD', nvl(gb.project_to_date_dr, 0) -
3796 nvl(gb.project_to_date_cr, 0) +
3797 nvl(gb.period_net_dr, 0) - nvl(gb.period_net_cr, 0), 0))
3798 from gl_bc_period_map pm,
3799 gl_balances gb
3800 -- ## selecting the latest open period
3801 -- ## Changes made For fix in Bug 3243216
3802 /* (select effective_period_num e, period_name n,quarter_num q,
3803 period_year y, ledger_id s, application_id a from gl_period_statuses
3804 where
3805 ledger_id= g_ledger_id and application_id =101 and closing_status='O'
3806 and effective_period_num =
3807 (select max(effective_period_num) from
3808 gl_period_statuses where ledger_id= g_ledger_id and application_id =101 and
3809 closing_status='O'))X*/ --Bug 5644702
3810 WHERE
3811 --- X.s = gb.ledger_id and x.a =101 and
3812 -- ## changes for the bug 3243216
3813 gb.ledger_id = g_ledger_id
3814 and gb.code_combination_id = bp.code_combination_id
3815 and gb.currency_code = g_func_curr_code
3816 and gb.actual_flag = pm.actual_flag
3817 and (gb.budget_version_id is null
3818 or gb.budget_version_id = pm.budget_version_id)
3819 -- ## Bug 3243216 replacement below
3820 AND GB.period_name = PM.query_period_name
3821 -- commented out below part as now we are selecting transaction period
3822 -- based on latest open period and accordingly joining with gl_balances on query_period
3823 /* AND GB.period_name = decode (PM.boundary_code, 'S', PM.query_period_name,
3824 decode(GB.actual_flag,
3825 'B', PM.query_period_name,
3826 'A', decode(GREATEST(BP.period_year*10000+BP.period_num, l_effective_period_num),
3827 BP.period_year*10000+BP.period_num,
3828 decode(BP.amount_type,
3829 'PTD', PM.query_period_Name,
3830 'QTD', decode(BP.period_year,
3831 l_period_year, decode(BP.quarter_num,
3832 l_quarter_num, l_period_name,
3833 pm.query_period_name),
3834 PM.query_period_name),
3835 'YTD', decode(BP.period_year,
3836 l_period_year, l_period_name,
3837 PM.query_Period_name),
3838 'PJTD',decode(l_period_name,
3839 NULL, PM.query_Period_name, l_period_name),
3840 PM.query_period_name),
3841 PM.query_period_name),
3842 'E', PM.query_period_name)
3843 ) */
3844
3845 and pm.ledger_id = g_ledger_id
3846 -- and pm.transaction_period_name = bp.period_name
3847 and pm.transaction_period_name = decode(pm.actual_flag,
3848 'B', bp.period_name,
3849 'A', decode(GREATEST(BP.period_year*10000+BP.period_num, l_effective_period_num),
3850 BP.period_year*10000+BP.period_num,
3851 decode(BP.amount_type,
3852 'PTD', bp.period_name,
3853 'QTD', decode(BP.period_year,
3854 l_period_year, decode(BP.quarter_num,
3855 l_quarter_num, l_period_name,
3856 bp.period_name),
3857 bp.period_name),
3858 'YTD', decode(BP.period_year,
3859 l_period_year, l_period_name,
3860 bp.period_name),
3861 'PJTD',decode(l_period_name,
3862 NULL, bp.period_name, l_period_name),
3863 bp.period_name),
3864 bp.period_name),
3865 'E', bp.period_name)
3866 and pm.boundary_code between 'A' AND 'Z'
3867 and pm.boundary_code || '' in
3868 (bp.boundary_code, decode(bp.amount_type, 'YTD',
3869 decode(bp.template_id, null, decode(bp.account_type,
3870 'A', 'S', 'L', 'S', 'O', 'S'), 'S')))
3871 and (pm.budget_version_id is null
3872 or pm.budget_version_id = bp.funding_budget_version_id)
3873 )
3874 where bp.packet_id = g_packet_id
3875 and bp.result_code is null
3876 and bp.effect_on_funds_code = 'D'
3877 and bp.funds_check_level_code <> 'N'
3878 and bp.currency_code = decode(bp.actual_flag, 'B', g_func_curr_code,
3879 bp.currency_code)
3880 and bp.funding_budget_version_id = decode(bp.actual_flag, 'B',
3881 bp.budget_version_id,
3882 bp.funding_budget_version_id);
3883
3884
3885 -- =========================== FND LOG ===========================
3886 psa_utils.debug_other_string(g_state_level,l_full_path,
3887 ' Update posted balance in gl_bc_packets ' || SQL%ROWCOUNT );
3888 -- ========================= FND LOG =============================
3889
3890 -- Commit to release Lock on gl_bc_dual
3891 commit;
3892
3893
3894 -- Reestablish the Row Share Lock on gl_bc_dual2 to maintain data
3895 -- consistency between the Funds Checker Summarization and the Add/Delete
3896 -- Summary Accounts program
3897
3898 -- =========================== FND LOG ===========================
3899 psa_utils.debug_other_string(g_state_level,l_full_path,
3900 ' Lock table gl_bc_dual2 in row share mode nowait' );
3901 -- ========================= FND LOG =============================
3902 LOCK TABLE gl_bc_dual2 IN ROW SHARE MODE NOWAIT;
3903
3904 -- =========================== FND LOG ===========================
3905 psa_utils.debug_other_string(g_state_level,l_full_path,' RETURN -> TRUE ' );
3906 -- ========================= FND LOG =============================
3907 return(TRUE);
3908
3909
3910 EXCEPTION
3911
3912 WHEN OTHERS THEN
3913
3914 -- =========================== FND LOG ===========================
3915 psa_utils.debug_other_string(g_excep_level,l_full_path,' EXCEPTION WHEN OTHERS '|| SQLERRM );
3916 -- ========================= FND LOG =============================
3917
3918 if SQLCODE = -54 then
3919 message_token('PROCEDURE', 'Funds Checker');
3920 message_token('EVENT', 'Table Locked by another Process');
3921 add_message('SQLGL', 'GL_UNHANDLED_EXCEPTION');
3922 else
3923 message_token('PROCEDURE', 'Funds Checker');
3924 message_token('EVENT', SQLERRM);
3925 add_message('SQLGL', 'GL_UNHANDLED_EXCEPTION');
3926 end if;
3927
3928 -- =========================== FND LOG ===========================
3929 psa_utils.debug_other_string(g_excep_level,l_full_path,' RETURN -> FALSE ' );
3930 -- ========================= FND LOG =============================
3931 g_debug := g_debug||' GLXFGB Failed : '||SQLERRM;
3932
3933 return(FALSE);
3934
3935 END glxfgb;
3936
3937 /* ================================ GLXFRC ============================ */
3938
3939 -- Update Result Codes
3940
3941 -- Set the Result Code for each transaction in the packet by computing funds
3942 -- availability
3943 --
3944 -- In case of Overrides, update the result codes for the detail transactions,
3945 -- generated transactions and summary transactions if the Transaction Amount
3946 -- is less than or equal to the Override Amount
3947 --
3948 -- Update the Result Code for each detail transaction that causes one or
3949 -- more of its corresponding summary transactions to fail Funds Check or
3950 -- Funds Reservation
3951 --
3952 -- Update the Result Code for each detail transaction that has one or more
3953 -- of its associated proprietary or Budgetary transactions that fail
3954 -- Funds Check or Funds Reservation (only when USSGL Option is set)
3955
3956 -- Structure of the Result Codes :
3957 --
3958 -- Range Meaning
3959 -- -------- ------------------------------------------------------------
3960 -- P00 - P09 Pass; Does not reduce FA / Does not require FC
3961 -- P10 - P14 Pass; Normal Pass - Proprietary
3962 -- P15 - P19 Pass; Normal Pass - Budgetary
3963 -- P20 - P24 Pass; Pass with Warnings - Proprietary
3964 -- P25 - P29 Pass; Pass with Warnings - Budgetary
3965 -- F00 - F09 Fail; Insufficient Funds - Proprietary
3966 -- F10 - F19 Fail; Insufficient Funds - Budgetary
3967 -- F20 - F29 Fail; Validation Errors
3968
3969 -- Result Codes for Funds Reservation/Check :
3970 --
3971 -- Code Explanation
3972 -- ---- --------------------------------------------------------
3973 -- P00 This transaction does not reduce Funds available
3974 -- P01 This account does not require Funds Check
3975 -- P02 This budget transaction applies to a budget other than your
3976 -- Funding Budget
3977 -- P03 This foreign currency budget transaction does not
3978 -- require Funds Check
3979 -- P04 This summary transaction is created by the Add Summary Accounts
3980 -- program
3981 -- P05 This transaction passes Funds Check in Force Pass mode
3982 -- P10 This transaction passes Funds Check
3983 -- P15 This budgetary transaction passes Funds Check
3984 -- P20 This transaction fails Funds Check; advisory checking is in
3985 -- force
3986 -- P21 This transaction fails Funds Check; you overrode the failure
3987 -- P22 This detail transaction causes a summary account to fail
3988 -- Funds Check (advisory)
3989 -- P23 This summary account fails Funds Check; you overrode
3990 -- the detail(s)
3991 -- P25 This budgetary transaction fails Funds Check; advisory checking
3992 -- is in force
3993 -- P26 This budgetary transaction fails Funds Check; you overrode the
3994 -- failure
3995 -- P27 This budgetary transaction causes a summary account to fail
3996 -- to fail Funds Check (advisory)
3997 -- F00 This detail transaction fails Funds Check
3998 -- F01 This detail transaction causes a summary account to fail
3999 -- Funds Check
4000 -- F02 This summary account fails Funds Check
4001 -- F03 One or more earlier pending transactions cause this
4002 -- transaction to fail
4003 -- F04 This detail transaction fails and causes a summary account to
4004 -- fail Funds Check
4005 -- F05 One or more associated generated transactions cause this
4006 -- transaction to fail
4007 -- F06 One or more associated transactions cause this proprietary
4008 -- transaction to fail
4009 -- F10 This budgetary detail transaction fails Funds Check
4010 -- F11 This budgetary detail transaction causes a summary account to
4011 -- fail Funds Check
4012 -- F12 This budgetary summary account fails Funds Check
4013 -- F13 One or more earlier pending transactions cause the budgetary
4014 -- transaction to fail
4015 -- F14 This budgetary transaction fails and also causes a summary
4016 -- account to fail
4017 -- F15 One or more associated transactions cause this budgetary
4018 -- transaction to fail
4019 -- F20 This Accounting Flexfield does not exist
4020 -- F21 This Accounting Flexfield is disabled or out-of-date
4021 -- F22 This Accounting Flexfield does not allow detail posting
4022 -- F23 This Accounting Flexfield does not allow detail budget posting
4023 -- F24 This accounting period does not exist
4024 -- F25 This accounting period is neither Open nor Future Enterable
4025 -- F26 This accounting period is not within an open budget year
4026 -- F27 This budget is frozen
4027 -- F28 This USSGL transaction code is out-of-date
4028
4029 FUNCTION glxfrc RETURN BOOLEAN IS
4030
4031 cursor retcode is
4032 select decode(count(*),
4033 count(decode(substr(bp.result_code, 1, 1), 'P', 1)),
4034 decode(sign(count(decode(bp.result_code, 'P20', 1,
4035 'P22', 1,
4036 'P25', 1,
4037 'P27', 1,
4038 'P31', 1,
4039 'P35', 1,
4040 'P36', 1,
4041 'P37', 1,
4042 'P38', 1,
4043 'P39', 1))), 0, 'S', 1, 'A'),
4044 count(decode(substr(bp.result_code, 1, 1), 'F', 1)),
4045 'F', decode(g_partial_resv_flag, 'Y', 'P', 'F'))
4046 from gl_bc_packets bp
4047 where bp.packet_id = g_packet_id
4048 and bp.template_id is null;
4049
4050 l_ret_code gl_bc_packets.result_code%type;
4051
4052 -- Bug 5571064 .. Start
4053
4054 CURSOR c_get_failed_distributions(p_packet_id IN NUMBER) IS
4055 SELECT distinct bc.source_distribution_id_num_1
4056 FROM gl_bc_packets bc
4057 WHERE bc.packet_id = p_packet_id
4058 AND bc.result_code like 'F%';
4059
4060 TYPE source_dist_id_num_1_tbl_type IS TABLE OF gl_bc_packets.source_distribution_id_num_1%type INDEX BY binary_integer;
4061
4062 l_source_dist_id_num_1_tbl source_dist_id_num_1_tbl_type;
4063
4064 -- Bug 5571064 .. End
4065
4066 -- ========================= FND LOG ===========================
4067 l_full_path VARCHAR2(100);
4068 -- ========================= FND LOG ===========================
4069
4070 BEGIN
4071
4072 l_full_path := g_path || 'glxfrc';
4073
4074 -- =========================== FND LOG ===========================
4075 psa_utils.debug_other_string(g_state_level,l_full_path, ' GLXFRC - START' );
4076 -- ========================= FND LOG =============================
4077
4078 -- Update Result Code for all transactions in Packet
4079 update gl_bc_packets bp
4080 set bp.result_code =
4081 decode(bp.actual_flag || decode(bp.currency_code, g_func_curr_code,
4082 null, '1'), 'B1', 'P03',
4083 decode(bp.actual_flag || decode(bp.budget_version_id,
4084 bp.funding_budget_version_id, null, '1'), 'B1', 'P02',
4085 decode(bp.funds_check_level_code, 'N', 'P01',
4086 decode(bp.effect_on_funds_code, 'I', 'P00',
4087 decode(g_fcmode, 'F', 'P05', decode(bp.account_category_code,
4088 'P',
4089 decode(sign(
4090 ((nvl(bp.budget_posted_balance, 0) -
4091 nvl(bp.actual_posted_balance, 0) -
4092 nvl(bp.encumbrance_posted_balance, 0) +
4093 nvl(bp.budget_approved_balance, 0) -
4094 nvl(bp.actual_approved_balance, 0) -
4095 nvl(bp.encumbrance_approved_balance, 0) +
4096 nvl(bp.budget_pending_balance, 0) -
4097 nvl(bp.actual_pending_balance, 0) -
4098 nvl(bp.encumbrance_pending_balance, 0)) -
4099 ((nvl(bp.accounted_dr, 0) -
4100 nvl(bp.accounted_cr, 0)) *
4101 decode(bp.actual_flag, 'B', -1, 1)) +
4102 decode(sign(
4103 (nvl(bp.budget_posted_balance, 0) +
4104 nvl(bp.budget_approved_balance, 0) +
4105 nvl(bp.budget_pending_balance, 0)) *
4106 decode(bp.dr_cr_code, 'D', 1, -1)),
4107 -1, nvl(bp.tolerance_amount, 0),
4108 decode(bp.tolerance_percentage ||
4109 ';' || bp.tolerance_amount, ';', 0,
4110 ';' || bp.tolerance_amount,
4111 bp.tolerance_amount,
4112 bp.tolerance_percentage || ';',
4113 abs(nvl(bp.budget_posted_balance, 0) +
4114 nvl(bp.budget_approved_balance, 0) +
4115 nvl(bp.budget_pending_balance, 0)) *
4116 bp.tolerance_percentage/100,
4117 least(
4118 abs(nvl(bp.budget_posted_balance, 0) +
4119 nvl(bp.budget_approved_balance, 0) +
4120 nvl(bp.budget_pending_balance, 0)) *
4121 bp.tolerance_percentage/100,
4122 bp.tolerance_amount))) *
4123 decode(bp.dr_cr_code, 'D', 1, -1)) *
4124 decode(bp.dr_cr_code, 'D', 1, -1)), 1, 'P10',
4125 0, 'P10', decode(bp.funds_check_level_code,
4126 'D', 'P20',
4127 decode(sign(nvl(bp.template_id,
4128 -1)), 1, 'F02',
4129 decode(sign(
4130 ((nvl(bp.budget_posted_balance, 0) -
4131 nvl(bp.actual_posted_balance, 0) -
4132 nvl(bp.encumbrance_posted_balance, 0) +
4133 nvl(bp.budget_approved_balance, 0) -
4134 nvl(bp.actual_approved_balance, 0) -
4135 nvl(bp.encumbrance_approved_balance, 0)) -
4136 ((nvl(bp.accounted_dr, 0) -
4137 nvl(bp.accounted_cr, 0)) *
4138 decode(bp.actual_flag, 'B', -1, 1)) +
4139 decode(sign(
4140 (nvl(bp.budget_posted_balance, 0) +
4141 nvl(bp.budget_approved_balance, 0) +
4142 nvl(bp.budget_pending_balance, 0)) *
4143 decode(bp.dr_cr_code, 'D', 1, -1)),
4144 -1, nvl(bp.tolerance_amount, 0),
4145 decode(bp.tolerance_percentage || ';' ||
4146 bp.tolerance_amount, ';', 0,
4147 ';' || bp.tolerance_amount,
4148 bp.tolerance_amount,
4149 bp.tolerance_percentage || ';',
4150 abs(nvl(bp.budget_posted_balance, 0) +
4151 nvl(bp.budget_approved_balance, 0) +
4152 nvl(bp.budget_pending_balance, 0)) *
4153 bp.tolerance_percentage/100,
4154 least(
4155 abs(nvl(bp.budget_posted_balance, 0) +
4156 nvl(bp.budget_approved_balance, 0) +
4157 nvl(bp.budget_pending_balance, 0)) *
4158 bp.tolerance_percentage/100,
4159 bp.tolerance_amount))) *
4160 decode(bp.dr_cr_code, 'D', 1, -1)) *
4161 decode(bp.dr_cr_code, 'D', 1, -1)),
4162 -1, 'F00', 'F03')))),
4163 'B',
4164 decode(sign(
4165 ((nvl(bp.actual_posted_balance, 0) +
4166 nvl(bp.actual_approved_balance, 0) +
4167 nvl(bp.actual_pending_balance, 0)) -
4168 ((nvl(bp.accounted_cr, 0) -
4169 nvl(bp.accounted_dr, 0)))) *
4170 decode(bp.dr_cr_code, 'D', 1, -1)), 1, 'P15',
4171 0, 'P15',
4172 decode(bp.funds_check_level_code, 'D', 'P25',
4173 decode(sign(nvl(bp.template_id, -1)),
4174 1, 'F12',
4175 decode(sign(
4176 ((nvl(bp.actual_posted_balance, 0) +
4177 nvl(bp.actual_approved_balance, 0)) -
4178 ((nvl(bp.accounted_cr, 0) -
4179 nvl(bp.accounted_dr, 0)))) *
4180 decode(bp.dr_cr_code, 'D', 1, -1)),
4181 -1, 'F10', 'F13'))))))))))
4182 where bp.packet_id = g_packet_id
4183 and (bp.result_code is null
4184 or g_fcmode = 'F' );
4185
4186
4187
4188 -- =========================== FND LOG ===========================
4189 psa_utils.debug_other_string(g_state_level,l_full_path, ' Update Result Code gl_bc_packets 1 updated -> ' || SQL%ROWCOUNT || ' rows');
4190 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_fcmode -> ' || g_fcmode);
4191 -- ========================= FND LOG =============================
4192
4193 /* -------------------------------------------------------------------+
4194 | Updating result code to F78 id funds check is failed and absolute|
4195 | Funds checking is done when there were no Budget Assignment |
4196 | Bug 5242198 |
4197 +-----------------------------------------------------------------*/
4198
4199 if(nvl(g_enable_efc_flag,'N')='Y') THEN
4200
4201 UPDATE gl_bc_packets bp
4202 set result_code='F78'
4203 WHERE bp.packet_id = g_packet_id
4204 AND bp.result_code like 'F%'
4205 AND bp.funding_budget_version_id IS NULL
4206 AND bp.funds_check_level_code = 'B';
4207
4208 end if;
4209 -- If Mode is Force Pass, there is no need for detail/summary and
4210 -- originating/generated tie back logic
4211
4212 if g_fcmode = 'F' then
4213 -- =========================== FND LOG ===========================
4214 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_fcmode = F -> goto normal_exit');
4215 -- ========================= FND LOG =============================
4216 goto normal_exit;
4217 end if;
4218
4219
4220 if g_summarized_flag then
4221
4222 -- =========================== FND LOG ===========================
4223 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_summarized_flag -> TRUE ');
4224 -- ========================= FND LOG =============================
4225
4226 -- Update Result Code for Detail Transactions when Summary Transactions
4227 -- fail Funds Check and Checking is Absolute
4228
4229 update gl_bc_packets bp
4230 set bp.result_code =
4231 decode(bp.account_category_code || substr(bp.result_code, 1, 1),
4232 'PP', 'F01', 'PF', 'F04', 'BP', 'F11', 'BF', 'F14')
4233 where bp.packet_id = g_packet_id
4234 and bp.template_id is null
4235 and (bp.result_code like 'P%'
4236 or bp.result_code in ('F00', 'F03', 'F10', 'F13'))
4237 and exists
4238 (
4239 select
4240
4241 'Summary Row exists and fails Funds Check; Absolute'
4242 from gl_bc_packets pk,
4243 gl_account_hierarchies ah
4244 where ah.ledger_id = bp.ledger_id
4245 and ah.summary_code_combination_id = pk.code_combination_id
4246 and ah.detail_code_combination_id = bp.code_combination_id
4247 and pk.packet_id = bp.packet_id
4248 and pk.actual_flag = bp.actual_flag
4249 and pk.period_name = bp.period_name
4250 and pk.je_source_name = bp.je_source_name
4251 and pk.je_category_name = bp.je_category_name
4252 and (pk.budget_version_id is null
4253 or pk.budget_version_id = bp.budget_version_id)
4254 and pk.account_category_code = bp.account_category_code
4255 and pk.funds_check_level_code = 'B'
4256 and pk.result_code in ('F02', 'F12')
4257 );
4258
4259 -- =========================== FND LOG ===========================
4260 psa_utils.debug_other_string(g_state_level,l_full_path, ' update gl_bc_packets 2 updated -> ' || SQL%ROWCOUNT || ' rows');
4261 -- ========================= FND LOG =============================
4262
4263 -- Update Result Code for Detail Transactions when Summary Transactions
4264 -- fail Funds Check and Checking is Advisory
4265
4266 update gl_bc_packets bp
4267 set bp.result_code =
4268 decode(bp.account_category_code, 'P', 'P22', 'B', 'P27')
4269 where bp.packet_id = g_packet_id
4270 and bp.template_id is null
4271 and bp.result_code like 'P%'
4272 and exists
4273 (
4274 select
4275
4276 'Summary Row exists and fails Funds Check; Advisory'
4277 from gl_account_hierarchies ah,
4278 gl_bc_packets pk
4279 where ah.ledger_id = bp.ledger_id
4280 and ah.summary_code_combination_id = pk.code_combination_id
4281 and ah.detail_code_combination_id = bp.code_combination_id
4282 and pk.packet_id = bp.packet_id
4283 and pk.actual_flag = bp.actual_flag
4284 and pk.period_name = bp.period_name
4285 and pk.je_source_name = bp.je_source_name
4286 and pk.je_category_name = bp.je_category_name
4287 and (pk.budget_version_id is null
4288 or pk.budget_version_id = bp.budget_version_id)
4289 and pk.account_category_code = bp.account_category_code
4290 and pk.funds_check_level_code = 'D'
4291 and pk.result_code in ('P20', 'P25')
4292 );
4293
4294 -- =========================== FND LOG ===========================
4295 psa_utils.debug_other_string(g_state_level,l_full_path, ' update gl_bc_packets 3 updated -> ' || SQL%ROWCOUNT || ' rows');
4296 -- ========================= FND LOG =============================
4297
4298 end if;
4299
4300
4301 -- Update Result Code of Original Proprietary Transaction when one or
4302 -- more of the associated Generated Transactions fail Funds Check and
4303 -- vice versa
4304
4305 if g_ussgl_option_flag then
4306
4307 -- =========================== FND LOG ===========================
4308 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_ussgl_option_flag -> TRUE');
4309 -- ========================= FND LOG =============================
4310
4311 update gl_bc_packets bp
4312 set bp.result_code =
4313 decode(bp.ussgl_transaction_code, null,
4314 decode(bp.account_category_code, 'P', 'F06', 'B', 'F15'),
4315 'F05')
4316 where bp.packet_id = g_packet_id
4317 and bp.template_id is null
4318 and bp.result_code like 'P%'
4319 and (bp.ussgl_transaction_code is not null
4320 or bp.ussgl_link_to_parent_id is not null)
4321 and exists
4322 (
4323 select 'One or more Proprietary/Budgetary counterparts of ' ||
4324 'this transaction exists and fails Funds Check'
4325 from gl_bc_packets pk
4326 where pk.packet_id = g_packet_id
4327 and pk.template_id is null
4328 and pk.result_code like 'F%'
4329 and (pk.ussgl_parent_id = bp.ussgl_link_to_parent_id
4330 or pk.ussgl_link_to_parent_id in (bp.ussgl_link_to_parent_id, bp.ussgl_parent_id))
4331 );
4332
4333 -- =========================== FND LOG ===========================
4334 psa_utils.debug_other_string(g_state_level,l_full_path, ' update gl_bc_packets 4 updated -> ' || SQL%ROWCOUNT || ' rows');
4335 -- ========================= FND LOG =============================
4336
4337 end if;
4338
4339 -- New logic added here for sub-ledger teams to populate full set of
4340 -- result codes. This is applicable to GL only if called from a
4341 -- concurrent program because in case of concurrent program the override
4342 -- functionality will be disabled even for GL.
4343
4344 IF g_calling_prog_flag = 'S' OR g_conc_flag THEN
4345
4346 IF g_override_flag THEN
4347
4348 if not glxfor then
4349 -- =========================== FND LOG ===========================
4350 psa_utils.debug_other_string(g_state_level,l_full_path, ' glxfor --> RETURN FALSE -> goto fatal_error');
4351 -- ========================= FND LOG =============================
4352 return false;
4353 end if;
4354 END IF;
4355
4356 open retcode;
4357 fetch retcode into l_ret_code;
4358 close retcode;
4359
4360 if ((g_fcmode in ('R', 'U', 'A')) and
4361 (g_summarized_flag) and
4362 (l_ret_code in ('S', 'A'))) then
4363
4364 -- ========================= FND LOG ===========================
4365 psa_utils.debug_other_string(g_state_level,l_full_path, ' inside Ist IF ');
4366 -- ========================= FND LOG ===========================
4367
4368 update gl_bc_packets bp
4369 set bp.result_code = 'P23'
4370 where bp.packet_id = g_packet_id
4371 and bp.result_code like 'F%'
4372 and bp.template_id is not null;
4373
4374 -- ========================= FND LOG ===========================
4375 psa_utils.debug_other_string(g_state_level,l_full_path, ' update gl_bc_packets 5 updated -> ' || SQL%ROWCOUNT || ' rows');
4376 -- ========================= FND LOG ===========================
4377
4378 end if;
4379
4380 update gl_bc_packets bp
4381 set bp.status_code = decode(bp.status_code || l_ret_code,
4382 'PF', 'R',
4383 'CF', 'F',
4384 decode(bp.status_code || substr(bp.result_code, 1, 1),
4385 'PF', 'R',
4386 'CF', 'F',
4387 bp.status_code)
4388 ),
4389 bp.last_update_date = sysdate
4390 where bp.packet_id = g_packet_id;
4391
4392 -- ========================= FND LOG ===========================
4393 psa_utils.debug_other_string(g_state_level,l_full_path, ' update gl_bc_packets 6 updated -> ' || SQL%ROWCOUNT || ' rows');
4394 -- ========================= FND LOG ===========================
4395
4396 END IF;
4397
4398 -- Update all lines to failure in same packet and same distribution if any other line fails.
4399 -- Bug 5250753
4400 -- Bug 5571064
4401
4402 OPEN c_get_failed_distributions (g_packet_id);
4403 FETCH c_get_failed_distributions bulk collect into l_source_dist_id_num_1_tbl;
4404
4405 FORALL I IN 1..l_source_dist_id_num_1_tbl.count
4406 UPDATE gl_bc_packets pk
4407 SET result_code ='F77'
4408 WHERE pk.packet_id = g_packet_id
4409 AND pk.source_distribution_id_num_1 = l_source_dist_id_num_1_tbl(I)
4410 AND pk.result_code like 'P%';
4411
4412 -- ========================= FND LOG ===========================
4413 psa_utils.debug_other_string(g_state_level,l_full_path,
4414 ' update gl_bc_packets 6.1, result_code to F77 for same packet and same distribution updated -> ' || SQL%ROWCOUNT || ' rows');
4415 -- ========================= FND LOG ===========================
4416
4417 CLOSE c_get_failed_distributions;
4418
4419 -- Bug 3553142
4420 -- If there is an advisory warning on any row in gl_bc_packets, all passed rows should indicate
4421 -- that one or more related lines have advisory warnings.
4422 -- Created 2 new LOOKUP_CODEs P12, P17
4423
4424 UPDATE gl_bc_packets pk
4425 SET result_code = 'P12'
4426 WHERE pk.packet_id = g_packet_id
4427 AND result_code = 'P10'
4428 AND exists (SELECT 'x'
4429 FROM gl_bc_packets bc
4430 WHERE bc.packet_id = pk.packet_id
4431 AND bc.result_code = 'P20');
4432
4433 -- ========================= FND LOG ===========================
4434 psa_utils.debug_other_string(g_state_level,l_full_path, ' update gl_bc_packets 7 updated -> ' || SQL%ROWCOUNT || ' rows');
4435 -- ========================= FND LOG ===========================
4436
4437
4438 UPDATE gl_bc_packets pk
4439 SET result_code = 'P17'
4440 WHERE pk.packet_id = g_packet_id
4441 AND result_code = 'P15'
4442 AND exists (SELECT 'x'
4443 FROM gl_bc_packets bc
4444 WHERE bc.packet_id = pk.packet_id
4445 AND bc.result_code = 'P25');
4446
4447 -- ========================= FND LOG ===========================
4448 psa_utils.debug_other_string(g_state_level,l_full_path, ' update gl_bc_packets 8 updated -> ' || SQL%ROWCOUNT || ' rows');
4449 -- ========================= FND LOG ===========================
4450
4451
4452 -- =========================== FND LOG ===========================
4453 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN -> TRUE');
4454 -- ========================= FND LOG =============================
4455
4456 return(TRUE);
4457
4458 <<normal_exit>>
4459 -- =========================== FND LOG ===========================
4460 psa_utils.debug_other_string(g_state_level,l_full_path, ' Reached label normal exit');
4461 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN -> TRUE');
4462 -- ========================= FND LOG =============================
4463
4464 return(TRUE);
4465
4466 EXCEPTION
4467
4468 WHEN OTHERS THEN
4469 -- =========================== FND LOG ===========================
4470 psa_utils.debug_other_string(g_excep_level,l_full_path, ' EXCEPTION WHEN OTHERS ' || SQLERRM);
4471 -- ========================= FND LOG =============================
4472
4473 message_token('PROCEDURE', 'Funds Checker');
4474 message_token('EVENT', SQLERRM);
4475 add_message('SQLGL', 'GL_UNHANDLED_EXCEPTION');
4476
4477 -- =========================== FND LOG ===========================
4478 psa_utils.debug_other_string(g_excep_level,l_full_path, ' RETURN -> FALSE');
4479 -- ========================= FND LOG =============================
4480 g_debug := g_debug||' GLXFRC Failed : '||SQLERRM;
4481 return(FALSE);
4482
4483 END glxfrc;
4484
4485 /* ============================= GLZCBC =============================== */
4486
4487 FUNCTION glzcbc RETURN NUMBER IS
4488
4489 cbc_fck_stmt VARCHAR2(2000);
4490 p_ledger_id NUMBER(15);
4491 p_packet_id NUMBER(15);
4492 p_conc_proc VARCHAR2(1);
4493 p_mode VARCHAR2(1);
4494 cbc_code NUMBER(15);
4495
4496 -- ========================= FND LOG ===========================
4497 l_full_path VARCHAR2(100);
4498 -- ========================= FND LOG ===========================
4499 BEGIN
4500
4501 p_conc_proc := 'F';
4502 l_full_path := g_path || 'glzcbc.';
4503
4504 -- =========================== FND LOG ===========================
4505 psa_utils.debug_other_string(g_state_level,l_full_path, ' GLZCBC - START' );
4506 -- ========================= FND LOG =============================
4507
4508 cbc_fck_stmt :=
4509 'BEGIN :ret_code := IGC_CBC_GL_FC_PKG.glzcbc(:packet_id,p_ledger_id,:mode,:conc_proc); END;';
4510
4511 -- =========================== FND LOG ===========================
4512 psa_utils.debug_other_string(g_state_level,l_full_path, ' cbc_fck_stmt -> ' || cbc_fck_stmt );
4513 -- ========================= FND LOG =============================
4514
4515 -- Assign parameter values before calling IGC
4516
4517 p_ledger_id := g_ledger_id;
4518 p_packet_id := g_packet_id;
4519 p_mode := g_fcmode;
4520
4521 -- =========================== FND LOG ===========================
4522 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_ledger_id -> ' || g_ledger_id );
4523 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_packet_id -> ' || g_packet_id );
4524 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_fcmode -> ' || g_fcmode );
4525 -- ========================= FND LOG =============================
4526
4527 execute immediate cbc_fck_stmt
4528 USING IN OUT cbc_code,IN p_packet_id,IN p_ledger_id,IN p_mode,IN p_conc_proc;
4529
4530 -- =========================== FND LOG ===========================
4531 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN cbc_code -> ' || cbc_code );
4532 -- ========================= FND LOG =============================
4533
4534 RETURN cbc_code;
4535
4536 EXCEPTION
4537 WHEN OTHERS THEN
4538
4539 -- =========================== FND LOG ===========================
4540 psa_utils.debug_other_string(g_excep_level,l_full_path, ' RETURN -> 1' );
4541 -- ========================= FND LOG =============================
4542
4543 RETURN 1;
4544
4545 END glzcbc;
4546
4547 /* ================================ GLZGCHK ========================== */
4548
4549 -- Callout to Grants Funds Check extension. The resulting Return Code
4550 -- is returned back through an out parameter. Any error in processing
4551 -- results in a return value from the function of FALSE.
4552
4553 FUNCTION glzgchk RETURN BOOLEAN IS
4554
4555 gms_stmt VARCHAR2(400);
4556
4557 -- ========================= FND LOG ===========================
4558 l_full_path VARCHAR2(100);
4559 -- ========================= FND LOG ===========================
4560
4561 BEGIN
4562
4563 l_full_path := g_path || 'glzgchk';
4564
4565 -- =========================== FND LOG ===========================
4566 psa_utils.debug_other_string(g_state_level,l_full_path, ' GLZGCHK - START' );
4567 -- ========================= FND LOG =============================
4568
4569 gms_stmt :=
4570 'BEGIN '||
4571 ' GMS_UTILITY.GMS_UTIL_PC_FCK('||
4572 ':g_ledger_id, :g_packet_id, :g_fcmode, '||
4573 '''N'', :g_partial_resv_flag, '||
4574 'FND_GLOBAL.USER_ID, FND_GLOBAL.RESP_ID, '||
4575 '''N'', :gms_retcode); '||
4576 'END;';
4577
4578 -- =========================== FND LOG ===========================
4579 psa_utils.debug_other_string(g_state_level,l_full_path, ' gms_stmt -> ' || gms_stmt );
4580 -- ========================= FND LOG =============================
4581
4582 execute immediate gms_stmt using g_ledger_id, g_packet_id, g_fcmode,
4583 g_partial_resv_flag, in out gms_retcode;
4584
4585 -- =========================== FND LOG ===========================
4586 psa_utils.debug_other_string(g_state_level,l_full_path, ' gms_retcode -> ' || gms_retcode );
4587 -- ========================= FND LOG =============================
4588
4589 IF NOT gms_retcode = '~'
4590 AND gms_retcode IS NOT NULL THEN
4591 -- =========================== FND LOG ===========================
4592 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN -> TRUE' );
4593 -- ========================= FND LOG =============================
4594 RETURN(TRUE);
4595 END IF;
4596
4597 -- =========================== FND LOG ===========================
4598 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN -> FALSE' );
4599 -- ========================= FND LOG =============================
4600 RETURN(FALSE);
4601
4602 EXCEPTION
4603
4604 WHEN OTHERS THEN
4605
4606 -- =========================== FND LOG ===========================
4607 psa_utils.debug_other_string(g_excep_level,l_full_path, ' EXCEPTION WHEN OTHER '|| SQLERRM );
4608 -- ========================= FND LOG =============================
4609
4610 /* Even when an SQL exception is raised, if the gms_retcode */
4611 /* has been set, indicate that processing has completed. */
4612 /* This ensures that any cleanup that needs to be done by */
4613 /* the GMS_RETURN_CODE processor is at least attempted. */
4614
4615 IF NOT gms_retcode = '~'
4616 AND gms_retcode IS NOT NULL THEN
4617 -- =========================== FND LOG ===========================
4618 psa_utils.debug_other_string(g_excep_level,l_full_path, ' RETURN -> TRUE' );
4619 -- ========================= FND LOG =============================
4620 RETURN(TRUE);
4621 ELSE
4622 -- =========================== FND LOG ===========================
4623 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN -> FALSE' );
4624 -- ========================= FND LOG =============================
4625 RETURN(FALSE);
4626 END IF;
4627
4628 END glzgchk;
4629
4630 /* ================================ GLZPAFCK =========================== */
4631
4632 -- Callout to Projects Funds Check extension. The resulting Return Code
4633 -- is returned back through an out parameter. Any error in processing
4634 -- results in a return value from the function of FALSE.
4635
4636 FUNCTION glzpafck RETURN BOOLEAN IS
4637
4638 pa_stmt VARCHAR2(400);
4639 cur_pa INTEGER;
4640 ignore INTEGER;
4641
4642 pa_retcode gl_bc_packets.result_code%TYPE;
4643 err_msg VARCHAR2(1024);
4644 err_stg VARCHAR2(1024);
4645
4646 -- ========================= FND LOG ===========================
4647 l_full_path VARCHAR2(100);
4648 -- ========================= FND LOG ===========================
4649 BEGIN
4650
4651 l_full_path := g_path || 'glzpafck.';
4652
4653 -- ========================= FND LOG ===========================
4654 psa_utils.debug_other_string(g_state_level,l_full_path, ' GLZPAFCK --> START ');
4655 -- ========================= FND LOG ===========================
4656
4657 pa_stmt :=
4658 'BEGIN '||
4659 ' PA_FUNDS_CONTROL_PKG.PA_FUNDS_CHECK(:gl_var, :g_ledger_id_var, :g_packet_id_var, '||
4660 ':g_fcmode_var, :g_partial_resv_flag_var, NULL, NULL,:pa_retcode, :err_msg, :err_stg); '||
4661 'END;';
4662
4663 -- ========================= FND LOG ===========================
4664 psa_utils.debug_other_string(g_state_level,l_full_path, ' pa_stmt -> ' || pa_stmt);
4665 -- ========================= FND LOG ===========================
4666
4667 EXECUTE IMMEDIATE pa_stmt USING 'GL', g_ledger_id, g_packet_id, g_fcmode,
4668 g_partial_resv_flag, OUT pa_retcode,
4669 OUT err_msg, OUT err_stg;
4670
4671 IF err_msg IS NOT NULL THEN
4672 -- ========================= FND LOG ===========================
4673 psa_utils.debug_other_string(g_state_level,l_full_path, ' pa_retcode -> ' || pa_retcode);
4674 psa_utils.debug_other_string(g_state_level,l_full_path, ' err_msg -> ' || err_msg);
4675 psa_utils.debug_other_string(g_state_level,l_full_path, ' err_stg -> ' || err_stg);
4676 -- ========================= FND LOG ===========================
4677 END IF;
4678
4679 IF (pa_retcode IS NULL) OR (pa_retcode = 'T') THEN
4680 -- ========================= FND LOG ===========================
4681 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN -> FALSE ');
4682 -- ========================= FND LOG ===========================
4683 g_debug := g_debug||' GLZPAFCK Failed : (PA_RETCODE IS NULL OR PA_RETCODE = T)';
4684 RETURN(FALSE);
4685 END IF;
4686
4687 -- ========================= FND LOG ===========================
4688 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN -> TRUE ');
4689 -- ========================= FND LOG ===========================
4690
4691 RETURN(TRUE);
4692
4693 EXCEPTION
4694
4695 WHEN OTHERS THEN
4696 -- ========================= FND LOG ===========================
4697 psa_utils.debug_other_string(g_excep_level,l_full_path, ' EXCEPTION WHEN OTHERS ');
4698 -- ========================= FND LOG ===========================
4699
4700 /* Even when an SQL exception is raised, if the pa_retcode */
4701 /* has been set, indicate that processing has completed. */
4702
4703 IF pa_retcode = 'T' THEN
4704 -- ========================= FND LOG ===========================
4705 psa_utils.debug_other_string(g_excep_level,l_full_path, ' RETURN -> FALSE ');
4706 -- ========================= FND LOG ===========================
4707 g_debug := g_debug||' GLZPAFCK Failed : PA_RETCODE = T';
4708 RETURN(FALSE);
4709 END IF;
4710
4711 -- ========================= FND LOG ===========================
4712 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN -> TRUE ');
4713 -- ========================= FND LOG ===========================
4714
4715 RETURN(TRUE);
4716
4717 END glzpafck;
4718
4719 /* =========================== GLXFOR =================================== */
4720
4721 -- Update the Result Codes for all Detail Transactions to 'P21' and the
4722 -- corresponding Generated Transactions to 'P26', if the Transaction Amount
4723 -- is less than or equal to the Override Amount for the Detail Transaction;
4724 -- Result Codes for Summary Transactions are updated in glxfrs()
4725
4726 FUNCTION glxfor RETURN BOOLEAN IS
4727 -- ========================= FND LOG ===========================
4728 l_full_path VARCHAR2(100);
4729 -- ========================= FND LOG ===========================
4730 BEGIN
4731
4732 l_full_path := g_path || 'glxfor';
4733
4734 -- ========================= FND LOG ===========================
4735 psa_utils.debug_other_string(g_state_level, l_full_path, ' GLXFOR --> START ');
4736 -- ========================= FND LOG ===========================
4737
4738 -- Update Result Code for Detail Transactions
4739
4740 update gl_bc_packets bp
4741 set bp.result_code = 'P21'
4742 where bp.packet_id = g_packet_id
4743 and bp.result_code between 'F00' and 'F19'
4744 and bp.ussgl_link_to_parent_id is null
4745 and bp.template_id is null
4746 and nvl(bp.override_amount, -1) >=
4747 abs(nvl(bp.accounted_dr, 0) - nvl(bp.accounted_cr, 0))
4748 and not exists
4749 (
4750 select 'If Partial Resv disallowed then all non-generated ' ||
4751 'detail lines that failed with any validation errors ' ||
4752 'or because of Funds Availability'
4753 from gl_bc_packets pk
4754 where pk.packet_id = g_packet_id
4755 and pk.template_id is null
4756 and pk.result_code like 'F%'
4757 and ((g_partial_resv_flag = 'N'
4758 and pk.ussgl_link_to_parent_id is null
4759 and (pk.result_code between 'F20' and 'F29'
4760 or nvl(pk.override_amount, -1) <
4761 abs(nvl(pk.accounted_dr, 0) - nvl(pk.accounted_cr, 0))))
4762 or (pk.ussgl_link_to_parent_id = bp.ussgl_parent_id
4763 and pk.result_code between 'F20' and 'F29'))
4764 );
4765
4766 -- ========================= FND LOG ===========================
4767 psa_utils.debug_other_string(g_state_level,l_full_path, ' Update gl_bc_packets1 -> ' || SQL%ROWCOUNT);
4768 -- ========================= FND LOG ===========================
4769
4770 -- ========================= FND LOG ===========================
4771 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_calling_prog_flag -> ' || g_calling_prog_flag);
4772 -- ========================= FND LOG ===========================
4773
4774
4775 IF (g_calling_prog_flag = 'G') THEN
4776
4777 -- Update Result Code for Generated Transactions
4778
4779 update gl_bc_packets bp
4780 set bp.result_code = 'P26'
4781 where bp.packet_id = g_packet_id
4782 and bp.result_code between 'F00' and 'F19'
4783 and bp.ussgl_link_to_parent_id is not null
4784 and exists
4785 (
4786 select 'Corresp Original Transaction which was Overridden'
4787 from gl_bc_packets pk
4788 where pk.packet_id = g_packet_id
4789 and pk.ussgl_parent_id = bp.ussgl_link_to_parent_id
4790 and pk.result_code = 'P21'
4791 );
4792
4793 END IF;
4794
4795 -- ========================= FND LOG ===========================
4796 psa_utils.debug_other_string(g_state_level,l_full_path, ' Update gl_bc_packets2 -> ' || SQL%ROWCOUNT);
4797 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN -> TRUE ');
4798 -- ========================= FND LOG ===========================
4799
4800 return(TRUE);
4801
4802
4803 EXCEPTION
4804
4805 WHEN OTHERS THEN
4806 -- ========================= FND LOG ===========================
4807 psa_utils.debug_other_string(g_excep_level,l_full_path, ' WHEN OTHERS EXCEPTION ' || SQLERRM);
4808 -- ========================= FND LOG ===========================
4809
4810 message_token('PROCEDURE', 'Funds Checker');
4811 message_token('EVENT', SQLERRM);
4812 add_message('SQLGL', 'GL_UNHANDLED_EXCEPTION');
4813
4814 -- ========================= FND LOG ===========================
4815 psa_utils.debug_other_string(g_excep_level,l_full_path, ' RETURN -> FALSE ');
4816 -- ========================= FND LOG ===========================
4817 g_debug := g_debug||' GLXFOR Failed : '||SQLERRM;
4818 return(FALSE);
4819
4820 END glxfor;
4821
4822 /* ================================= GLXFRS ============================ */
4823
4824 -- Get Return Status
4825
4826 -- Return Code can be of one of the following values :
4827 --
4828 -- Code Meaning Description
4829 -- ---- ------- ----------------------------------------
4830 -- S Success All transactions in packet pass Funds
4831 -- Check or Funds Reservation
4832 --
4833 -- A Advisory All transactions in packet pass Funds
4834 -- Check or Funds Reservation; but some
4835 -- with Advisory warnings
4836 --
4837 -- F Failure All transactions in packet fail Funds
4838 -- Check or Funds Reservation (partial
4839 -- reservation allowed)
4840 -- OR
4841 -- One or more transactions in packet fail
4842 -- Funds Check or Funds Reservation
4843 -- (partial reservation not allowed)
4844 --
4845 -- P Partial Only part of the transactions in packet
4846 -- pass Funds Check or Funds Reservation
4847 -- (partial reservation allowed only)
4848 --
4849 -- T Fatal Irrecoverable error detected that
4850 -- prevents funds check or reservation
4851 -- from proceeding
4852 --
4853 -- Decode count fragments :
4854 -- ------------------------
4855 -- count(*)
4856 -- - Total Number of Detail Transactions in packet
4857 --
4858 -- count(decode(substr(BP.result_code, 1, 1), 'P', 1))
4859 -- - Total Number of Detail Transactions with a pass Result Code
4860 --
4861 -- count(decode(BP.result_code,
4862 -- 'P20', 1, 'P22', 1, 'P25', 1, 'P27', 1))
4863 -- - Total Number of Detail Transactions that pass with Advisory warnings
4864 --
4865 -- count(decode(substr(BP.result_code, 1, 1), 'F', 1))
4866 -- - Total Number of Detail Transactions with a fail Result Code
4867
4868 FUNCTION glxfrs RETURN BOOLEAN IS
4869
4870 cursor retcode is
4871 select decode(count(*),
4872 count(decode(substr(bp.result_code, 1, 1), 'P', 1)),
4873 decode(sign(count(decode(bp.result_code,
4874 'P20', 1,
4875 'P22', 1,
4876 'P25', 1,
4877 'P27', 1,
4878 'P31', 1,
4879 'P35', 1,
4880 'P36', 1,
4881 'P37', 1,
4882 'P38', 1,
4883 'P39', 1))), 0, 'S', 1, 'A'),
4884 count(decode(substr(bp.result_code, 1, 1), 'F', 1)),
4885 'F', decode(g_partial_resv_flag, 'Y', 'P', 'F'))
4886 from gl_bc_packets bp
4887 where bp.packet_id = g_packet_id
4888 and bp.template_id is null;
4889
4890 -- ========================= FND LOG ===========================
4891 l_full_path VARCHAR2(100);
4892 -- ========================= FND LOG ===========================
4893
4894 BEGIN
4895
4896 l_full_path := g_path || 'glxfrs';
4897
4898 -- ========================= FND LOG ===========================
4899 psa_utils.debug_other_string(g_state_level,l_full_path, ' GLXFRS --> START ');
4900 -- ========================= FND LOG ===========================
4901
4902 -- Return Code for the Packet
4903
4904 open retcode;
4905 fetch retcode into g_return_code;
4906 close retcode;
4907
4908 -- ========================= FND LOG ===========================
4909 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_return_code --> ' || g_return_code);
4910 psa_utils.debug_other_string(g_state_level,l_full_path, ' Calling glrchk ');
4911 -- ========================= FND LOG ===========================
4912
4913 if not glrchk(g_return_code) then
4914 -- ========================= FND LOG ===========================
4915 psa_utils.debug_other_string(g_state_level,l_full_path, ' glrchk --> FALSE ');
4916 -- ========================= FND LOG ===========================
4917 return(FALSE);
4918 end if;
4919
4920 -- Update Status Code and Last Update Date for all transactions
4921
4922 -- Status Codes for Funds Reservation / Check :
4923 --
4924 -- (I) For return codes S(Success), A(Advisory) or F(Failure) :
4925 --
4926 -- Process Original Status Return Code Status Code
4927 -- ----------- --------------- ----------- ---------------
4928 -- Reservation P (Pending) S (Success) A (Approved)
4929 -- Reservation P (Pending) A (Advisory) A (Approved)
4930 -- Reservation P (Pending) F (Failure) R (Rejected)
4931 -- Checking C (Checking) S (Success) S (Passed Check)
4932 -- Checking C (Checking) A (Advisory) S (Passed Check)
4933 -- Checking C (Checking) F (Failure) F (Failed Check)
4934 --
4935 -- NOTE: When Partial Reservation is not allowed, all transactions
4936 -- in a packet are updated to the same Status Code.
4937 -- e.g individual lines with Pxx result codes within a
4938 -- Failure packet get R (Rejected) Status Codes
4939 --
4940 -- (II) For return code P(Partial) :
4941 --
4942 -- Process Original Status Result Code Status Code
4943 -- ----------- --------------- ----------- ---------------
4944 -- Reservation P (Pending) Pxx A (Approved)
4945 -- Reservation P (Pending) Fxx R (Rejected)
4946 -- Checking C (Checking) Pxx S (Passed Check)
4947 -- Checking C (Checking) Fxx F (Failed Check)
4948
4949 if g_calling_prog_flag = 'G' then
4950 update gl_bc_packets bp
4951 set bp.status_code = decode(bp.status_code || g_return_code, 'PS', 'A',
4952 'PA', 'A', 'PF', 'R', 'CS', 'S', 'CA', 'S',
4953 'CF', 'F',
4954 decode(bp.status_code ||
4955 substr(bp.result_code, 1, 1), 'PP', 'A',
4956 'PF', 'R', 'CP', 'S', 'CF', 'F', 'T')),
4957 bp.last_update_date = sysdate
4958 where bp.packet_id = g_packet_id;
4959 else
4960 update gl_bc_packets bp
4961 set bp.status_code = decode(bp.status_code || g_return_code, 'PS', 'A',
4962 'PA', 'A', 'PF', 'R', 'CS', 'S', 'CA', 'S',
4963 'CF', 'F',
4964 decode(bp.status_code ||
4965 substr(bp.result_code, 1, 1), 'PP', 'A',
4966 'PF', 'R', 'CP', 'S', 'CF', 'F',
4967 decode(bp.status_code, 'F', 'F', 'R', 'R', 'T'))),
4968 bp.last_update_date = sysdate
4969 where bp.packet_id = g_packet_id;
4970 end if;
4971
4972 -- ========================= FND LOG ===========================
4973 psa_utils.debug_other_string(g_state_level,l_full_path, ' update gl_bc_packets --> ' || SQL%ROWCOUNT);
4974 -- ========================= FND LOG ===========================
4975
4976 -- Update the Result Code of all Summary Transactions that fail Funds
4977 -- Reservation to 'P23', when each of their corresponding details got
4978 -- overridden in glxfor(). This Module executes this SQL only if
4979 -- all details in the packet PASS Funds (UN)RESERVATION, i.e. Return
4980 -- Code is 'S' (Success) or 'A' (Advisory); with at least one Summary
4981 -- Transaction present
4982 --
4983 -- Code Explanation
4984 -- ---- --------------------------------------------------------
4985 -- P23 This summary account fails funds check; you overrode
4986 -- the detail(s)
4987 --
4988
4989 -- ========================= FND LOG ===========================
4990 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_fcmode --> ' || g_fcmode);
4991 IF (g_summarized_flag) THEN
4992 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_summarized_flag --> TRUE ');
4993 ELSE
4994 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_summarized_flag --> FALSE ');
4995 END IF;
4996 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_return_code --> ' || g_return_code);
4997 -- ========================= FND LOG ===========================
4998
4999 if ((g_fcmode in ('R', 'U', 'A')) and
5000 (g_summarized_flag) and
5001 (g_return_code in ('S', 'A'))) then
5002
5003 -- ========================= FND LOG ===========================
5004 psa_utils.debug_other_string(g_state_level,l_full_path, ' inside Ist IF ');
5005 -- ========================= FND LOG ===========================
5006
5007 update gl_bc_packets bp
5008 set bp.result_code = 'P23'
5009 where bp.packet_id = g_packet_id
5010 and bp.result_code like 'F%'
5011 and bp.template_id is not null;
5012
5013 -- ========================= FND LOG ===========================
5014 psa_utils.debug_other_string(g_state_level,l_full_path, ' update gl_bc_packets --> ' || SQL%ROWCOUNT);
5015 -- ========================= FND LOG ===========================
5016
5017 end if;
5018
5019
5020 -- Resummarize Amounts for all Summary Transactions if the Return Code is
5021 -- Partial and Mode is Reservation
5022
5023 -- This is necessary for partially reserved packets since for all approved
5024 -- Summary Transactions, the corresponding Detail Transactions may be
5025 -- rejected and the over-accounted Summary Amounts would affect Funds
5026 -- Check and/or Reservation for packets arriving later
5027
5028 -- e.g : Detail Transactions D1 and D2 roll up to the same Summary
5029 -- Transaction S1
5030 --
5031 -- D1: $10 (Approved)
5032 -- D2: $20 (Rejected)
5033 -- -----------------------
5034 -- S1: $30 (Approved)
5035 --
5036 -- However, since only $10 of D1 is actually approved but not the
5037 -- $20 of D2, we should update the amount approved in S1 to $10
5038 --
5039 -- This SQL also resummarizes for any Rejected Summary Transaction where one
5040 -- of more of its corresponding Details were Overridden in glxfor().
5041 -- In this case, it also updates the Status Code and Result Code of
5042 -- these Summary Transactions to 'A' (Approved) and 'P23' respectively
5043 --
5044 -- Note: If the subquery of the correlated update returns no row, the
5045 -- default action (thru' the nvls) will update all the columns
5046 -- back to their original values
5047
5048 if ((g_fcmode in ('R', 'A', 'U')) and
5049 (g_summarized_flag) and
5050 (g_return_code = 'P')) then
5051 begin
5052
5053 -- ========================= FND LOG ===========================
5054 psa_utils.debug_other_string(g_state_level,l_full_path, ' inside IInd IF ');
5055 -- ========================= FND LOG ===========================
5056
5057 update gl_bc_packets bp
5058 set (bp.entered_dr,
5059 bp.entered_cr,
5060 bp.accounted_dr,
5061 bp.accounted_cr,
5062 bp.status_code,
5063 bp.result_code) =
5064 (
5065 select nvl(sum(nvl(pk.entered_dr, 0)), bp.entered_dr),
5066 nvl(sum(nvl(pk.entered_cr, 0)), bp.entered_cr),
5067 nvl(sum(nvl(pk.accounted_dr, 0)), bp.accounted_dr),
5068 nvl(sum(nvl(pk.accounted_cr, 0)), bp.accounted_cr),
5069 nvl(max(pk.status_code), 'R'),
5070 decode(max(pk.status_code), null, bp.result_code,
5071 decode(bp.status_code, 'A', bp.result_code, 'P23'))
5072 from gl_account_hierarchies ah,
5073 gl_bc_packets pk
5074 where ah.ledger_id = g_ledger_id
5075 and ah.template_id = bp.template_id
5076 and ah.summary_code_combination_id = bp.code_combination_id
5077 and ah.detail_code_combination_id = pk.code_combination_id
5078 and pk.packet_id = g_packet_id
5079 and pk.status_code = 'A'
5080 and pk.template_id is null
5081 and pk.actual_flag = bp.actual_flag
5082 and pk.period_name = bp.period_name
5083 and pk.currency_code = bp.currency_code
5084 and pk.je_source_name = bp.je_source_name
5085 and pk.je_category_name = bp.je_category_name
5086 and (pk.budget_version_id is null
5087 or pk.budget_version_id = bp.budget_version_id)
5088 and pk.account_category_code = bp.account_category_code
5089 )
5090 where bp.packet_id = g_packet_id
5091 and bp.template_id is not null;
5092
5093 -- ========================= FND LOG ===========================
5094 psa_utils.debug_other_string(g_state_level,l_full_path, ' update gl_bc_packets --> ' || SQL%ROWCOUNT);
5095 -- ========================= FND LOG ===========================
5096
5097 end;
5098 end if;
5099
5100 -- ========================= FND LOG ===========================
5101 psa_utils.debug_other_string(g_state_level,l_full_path, ' calling glxfar ');
5102 -- ========================= FND LOG ===========================
5103
5104 if not glxfar then
5105 -- ========================= FND LOG ===========================
5106 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN --> FALSE');
5107 -- ========================= FND LOG ===========================
5108 return(FALSE);
5109 end if;
5110
5111 -- ========================= FND LOG ===========================
5112 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN --> TRUE ');
5113 -- ========================= FND LOG ===========================
5114
5115 return(TRUE);
5116
5117 EXCEPTION
5118
5119 WHEN OTHERS THEN
5120
5121 if retcode%ISOPEN then
5122 close retcode;
5123 end if;
5124
5125 message_token('PROCEDURE', 'Funds Checker');
5126 message_token('EVENT', SQLERRM);
5127 add_message('SQLGL', 'GL_UNHANDLED_EXCEPTION');
5128
5129 -- ========================= FND LOG ===========================
5130 psa_utils.debug_other_string(g_excep_level,l_full_path, ' EXCEOPTION WHEN OTHERS '|| SQLERRM);
5131 psa_utils.debug_other_string(g_excep_level,l_full_path, ' RETURN --> FALSE ');
5132 -- ========================= FND LOG ===========================
5133 g_debug := g_debug||' GLXFRS Failed : '||SQLERRM;
5134 return(FALSE);
5135
5136 END glxfrs;
5137
5138 /* ================================= GLRCHK ======================== */
5139
5140 --
5141 -- Provide callout to reconcile Return Status and Posting results.
5142 --
5143 -- After computation of the General Ledger Funds Check overall status is
5144 -- completed within glxfrs(), other parties (Grants) need to have an
5145 -- opportunity to reconcile the status with their own computation.
5146 -- Additionally, other parties need confirmation that all Funds Check
5147 -- work is completed (to reflect this within their own systems) or that
5148 -- a Fatal Error has occurred.
5149 --
5150 -- glrchk() provides this centralize place to callout to these other parties.
5151 --
5152 -- Bug 2184578
5153 -- If Standard Budgetary Control failed, CBC Journals shoud not be committed.
5154 -- This is achieved by calling function IGC_CBC_GL_FC_PKG.reconcile_glzcbc
5155 --
5156
5157 FUNCTION glrchk(post_control IN gl_bc_packets.result_code%TYPE)
5158 RETURN BOOLEAN IS
5159
5160 -- ========================= FND LOG ===========================
5161 l_full_path VARCHAR2(100);
5162 -- ========================= FND LOG ===========================
5163
5164 BEGIN
5165 l_full_path := g_path || 'glrchk.';
5166
5167 -- ========================= FND LOG ===========================
5168 psa_utils.debug_other_string(g_state_level,l_full_path, ' glrchk --> START ');
5169 psa_utils.debug_other_string(g_state_level,l_full_path, ' post_control --> ' || post_control);
5170 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_cbc_retcode --> ' || g_cbc_retcode);
5171 -- ========================= FND LOG ===========================
5172
5173 /*========================+
5174 | CBC Reconcile |
5175 +========================*/
5176
5177 -- ========================= FND LOG ===========================
5178 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_cbc_retcode-> '||g_cbc_retcode);
5179 -- ========================= FND LOG ===========================
5180
5181
5182 IF g_cbc_retcode = 1 then
5183 -- ========================= FND LOG ===========================
5184 psa_utils.debug_other_string(g_state_level,l_full_path, ' Calling CBC Reconcile ');
5185 -- ========================= FND LOG ===========================
5186
5187 DECLARE
5188 cbc_recon_stmt VARCHAR2(2000);
5189 cbc_recon_code NUMBER(15);
5190
5191 BEGIN
5192 -- ========================= FND LOG ===========================
5193 psa_utils.debug_other_string(g_state_level,l_full_path, ' GLRCHK(CBCRECONCILE) --> START ');
5194 -- ========================= FND LOG ===========================
5195
5196 cbc_recon_stmt :=
5197 'BEGIN :ret_code := IGC_CBC_GL_FC_PKG.reconcile_glzcbc(:packet_id,:sob_id,:mode); END;';
5198
5199 -- ========================= FND LOG ===========================
5200 psa_utils.debug_other_string(g_state_level,l_full_path, ' cbc_recon_stmt --> ' || cbc_recon_stmt);
5201 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_ledger_id --> ' || g_ledger_id);
5202 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_packet_id --> ' || g_packet_id);
5203 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_mode --> ' || g_fcmode);
5204 -- ========================= FND LOG ===========================
5205
5206 execute immediate cbc_recon_stmt
5207 USING IN OUT cbc_recon_code,IN g_packet_id,IN g_ledger_id,IN g_fcmode;
5208
5209 -- ========================= FND LOG ===========================
5210 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN cbc_recon_code --> ' || cbc_recon_code);
5211 -- ========================= FND LOG ===========================
5212
5213 IF cbc_recon_code = -1 THEN
5214 g_debug := g_debug||' GLRCHK Failed : CBC_RECONC_CODE = -1';
5215 return false;
5216 END IF;
5217
5218 EXCEPTION
5219 WHEN OTHERS THEN
5220 NULL;
5221
5222 END;
5223
5224 END IF;
5225
5226 -- ========================= FND LOG ===========================
5227 IF (g_psa_grantcheck) THEN
5228 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_psa_grantcheck --> TRUE ');
5229 ELSE
5230 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_psa_grantcheck --> FALSE ');
5231 END IF;
5232 -- ========================= FND LOG ===========================
5233
5234 /*========================+
5235 | GMS Reconcile |
5236 +========================*/
5237
5238 IF g_psa_grantcheck THEN
5239
5240 -- ========================= FND LOG ===========================
5241 psa_utils.debug_other_string(g_state_level,l_full_path, ' Calling GMS Reconcile ');
5242 -- ========================= FND LOG ===========================
5243
5244 DECLARE
5245
5246 gms_stmt VARCHAR2(400);
5247 gl_retcode gl_bc_packets.result_code%TYPE;
5248 gms_control gl_bc_packets.result_code%TYPE;
5249
5250 BEGIN
5251 -- ========================= FND LOG ===========================
5252 psa_utils.debug_other_string(g_state_level,l_full_path, ' GLRCHK(GMS Reconcile) --> START ');
5253 psa_utils.debug_other_string(g_state_level,l_full_path, ' post_control -> ' || post_control);
5254 -- ========================= FND LOG ===========================
5255
5256 IF post_control = 'X' OR post_control = 'Z' THEN
5257 gl_retcode := g_return_code;
5258 gms_control := post_control;
5259 ELSE
5260 gl_retcode := post_control;
5261 gms_control := gms_retcode;
5262 END IF;
5263
5264 -- ========================= FND LOG ===========================
5265 psa_utils.debug_other_string(g_state_level,l_full_path, ' gl_retcode -> ' || gl_retcode);
5266 psa_utils.debug_other_string(g_state_level,l_full_path, ' gms_control -> ' || gms_control);
5267 -- ========================= FND LOG ===========================
5268
5269 gms_stmt :=
5270 'BEGIN '||
5271 ' GMS_UTILITY.GMS_UTIL_GL_RETURN_CODE(:g_packet_id, :g_fcmode, '||
5272 ':gl_retcode, :gms_control, :g_partial_resv_flag); '||
5273 'END;';
5274
5275 -- ========================= FND LOG ===========================
5276 psa_utils.debug_other_string(g_state_level,l_full_path, ' gms_stmt -> ' || gms_stmt);
5277 -- ========================= FND LOG ===========================
5278
5279 execute immediate gms_stmt using g_packet_id, g_fcmode, in out gl_retcode,
5280 gms_control, g_partial_resv_flag;
5281
5282 -- Given that the resulting return code makes sense, replace the
5283 -- context's return code with it.
5284
5285 IF gl_retcode IS NOT NULL AND gl_retcode <> 'Z' THEN
5286
5287 -- ========================= FND LOG ===========================
5288 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_return_code -> ' || g_return_code);
5289 psa_utils.debug_other_string(g_state_level,l_full_path, ' Goto -> GMS_RECONCILE_EXIT (Normal) ');
5290 -- ========================= FND LOG ===========================
5291
5292 g_return_code := gl_retcode;
5293 goto gms_reconcile_exit;
5294
5295 END IF;
5296
5297 -- ========================= FND LOG ===========================
5298 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN -> FALSE ');
5299 -- ========================= FND LOG ===========================
5300 g_debug := g_debug||' GLRCHK Failed';
5301 RETURN(FALSE);
5302
5303 <<GMS_RECONCILE_EXIT>>
5304 null;
5305 EXCEPTION
5306
5307 WHEN OTHERS THEN
5308
5309 -- ========================= FND LOG ===========================
5310 psa_utils.debug_other_string(g_excep_level,l_full_path, ' EXCEPTION WHEN OTHERS ' || SQLERRM);
5311 psa_utils.debug_other_string(g_excep_level,l_full_path, ' RETURN -> FALSE ');
5312 -- ========================= FND LOG ===========================
5313 g_debug := g_debug||' GLRCHK Failed : '||SQLERRM;
5314 RETURN(FALSE);
5315 END;
5316
5317 END IF;
5318
5319 -- ========================= FND LOG ===========================
5320 IF (g_psa_pacheck) THEN
5321 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_psa_pacheck --> TRUE ');
5322 ELSE
5323 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_psa_pacheck --> FALSE ');
5324 END IF;
5325 -- ========================= FND LOG ===========================
5326
5327 /*========================+
5328 | PA Reconcile |
5329 +========================*/
5330
5331 IF (g_psa_pacheck) AND (post_control = 'X') THEN
5332 -- ========================= FND LOG ===========================
5333 psa_utils.debug_other_string(g_state_level,l_full_path, ' calling glzpacfm ');
5334 -- ========================= FND LOG ===========================
5335
5336 DECLARE
5337
5338 pa_stmt VARCHAR2(400);
5339 err_stg VARCHAR2(1024);
5340
5341 BEGIN
5342 -- ========================= FND LOG ===========================
5343 psa_utils.debug_other_string(g_state_level,l_full_path, ' GLRCHK(GLZPAFCM) --> START ');
5344 -- ========================= FND LOG ===========================
5345
5346 pa_stmt :=
5347 'BEGIN '||
5348 ' PA_FUNDS_CONTROL_PKG.PA_GL_CBC_CONFIRMATION(:gl_var, :g_packet_id_var, '||
5349 ':g_fcmode_var, :g_partial_resv_flag_var, NULL, NULL,:gl_retcode, :err_stg); '||
5350 'END;';
5351
5352 -- ========================= FND LOG ===========================
5353 psa_utils.debug_other_string(g_state_level,l_full_path, ' pa_stmt -> ' || pa_stmt);
5354 -- ========================= FND LOG ===========================
5355
5356 -- ========================= FND LOG ===========================
5357 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_fcmode -> ' || g_fcmode);
5358 -- ========================= FND LOG ===========================
5359
5360 IF g_fcmode = 'U' THEN
5361 EXECUTE IMMEDIATE pa_stmt USING 'GL', g_packet_id_ursvd, g_fcmode,
5362 g_partial_resv_flag, IN OUT g_return_code, OUT err_stg;
5363 ELSE
5364 EXECUTE IMMEDIATE pa_stmt USING 'GL', g_packet_id, g_fcmode,
5365 g_partial_resv_flag, IN OUT g_return_code, OUT err_stg;
5366 END IF;
5367
5368 -- ========================= FND LOG ===========================
5369 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_return_code -> ' || g_return_code);
5370 psa_utils.debug_other_string(g_state_level,l_full_path, ' err_stg -> ' || err_stg);
5371 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN -> TRUE');
5372 -- ========================= FND LOG ===========================
5373
5374 EXCEPTION
5375
5376 WHEN OTHERS THEN
5377
5378 -- ========================= FND LOG ===========================
5379 psa_utils.debug_other_string(g_excep_level,l_full_path, ' WHEN OTHERS EXCEPTION' );
5380 -- ========================= FND LOG ===========================
5381
5382 /* Even when an SQL exception is raised, if the pa_retcode */
5383 /* has been set, indicate that processing has completed. */
5384
5385 -- ========================= FND LOG ===========================
5386 psa_utils.debug_other_string(g_excep_level,l_full_path, ' RETURN -> TRUE ');
5387 -- ========================= FND LOG ===========================
5388
5389 END;
5390
5391 END IF;
5392
5393 -- ========================= FND LOG ===========================
5394 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN --> TRUE ');
5395 -- ========================= FND LOG ===========================
5396
5397 RETURN(TRUE);
5398
5399 END glrchk;
5400
5401 /* ================================ GLXFJE =========================== */
5402
5403 -- Process Journal Entries
5404 -- If the Originating Batch is Actual, the associated generated Journal Lines
5405 -- are appended/deleted to/from the corresponding headers of the Batch; the
5406 -- Control and Running Totals of the Headers and the Batch are also updated
5407 -- If the Originating Batch is Encumbrance or Budget, a separate Actual Batch
5408 -- is created/deleted for the associated generated Journal Lines
5409 -- Assumption :
5410 --
5411 -- This Module assumes that the packet being processed only includes
5412 -- Transactions from 1 single GL Journal Batch for performance reasons.
5413 -- This is how we populate gl_bc_packets currently in all GL Implementations
5414
5415 FUNCTION glxfje RETURN BOOLEAN IS
5416
5417 l_je_batch_id gl_bc_packets.je_batch_id%TYPE;
5418 l_gen_batch_id gl_bc_packets.je_batch_id%TYPE;
5419 l_actual_flag gl_bc_packets.actual_flag%TYPE;
5420 l_max_je_line_num gl_bc_packets.je_line_num%TYPE; -- bug 5139224
5421
5422
5423 cursor orig_bat is
5424 select max(bp.je_batch_id),
5425 max(bp.actual_flag),
5426 max(bp.je_line_num) -- bug 5139224
5427 from gl_bc_packets bp
5428 where bp.packet_id = g_packet_id
5429 and bp.template_id is null
5430 and bp.ussgl_link_to_parent_id is null;
5431
5432 cursor generated_bat is
5433 select distinct bp.je_batch_id
5434 from gl_bc_packets bp
5435 where bp.packet_id = g_packet_id
5436 and bp.ussgl_link_to_parent_id is not null;
5437
5438 cursor batch_id is
5439 select gl_je_batches_s.nextval
5440 from dual;
5441
5442 cursor enable_approval is
5443 SELECT enable_je_approval_flag
5444 FROM gl_ledgers_public_v
5445 WHERE ledger_id = g_ledger_id;
5446
5447 cursor je_source(c_orig_batch_id IN NUMBER) is
5448 SELECT JH.je_source je_source
5449 FROM GL_JE_HEADERS JH
5450 WHERE JH.je_header_id =
5451 (SELECT min(JH1.je_header_id)
5452 FROM GL_JE_HEADERS JH1
5453 WHERE JH1.je_batch_id = c_orig_batch_id);
5454
5455 cursor je_approval (c_je_source IN VARCHAR2) is
5456 SELECT journal_approval_flag
5457 FROM GL_JE_SOURCES
5458 WHERE je_source_name = c_je_source;
5459
5460 cursor avoid_copy_dff_attr is
5461 SELECT 'Y'
5462 FROM FND_DESCRIPTIVE_FLEXS FD
5463 WHERE application_id = 101
5464 and descriptive_flexfield_name = 'GL_JE_LINES'
5465 and context_user_override_flag = 'N'
5466 and (UPPER(default_context_field_name) IN ('CONTEXT3', 'ACCOUNT_NUM'));
5467
5468
5469 l_je_source je_source%rowtype;
5470 l_enable_app enable_approval%rowtype;
5471 l_je_approval je_approval%rowtype;
5472 l_approval_status_code gl_je_batches.approval_status_code%type;
5473 l_reversal_method VARCHAR2(1);
5474 l_seg_val_ret_code NUMBER;
5475 l_avoid_copying_attr VARCHAR2(1);
5476
5477 -- ========================= FND LOG ===========================
5478 l_full_path VARCHAR2(100);
5479 -- ========================= FND LOG ===========================
5480
5481 BEGIN
5482
5483 l_full_path := g_path || 'glxfje';
5484
5485 -- ========================= FND LOG ===========================
5486 psa_utils.debug_other_string(g_state_level,l_full_path, ' GLXFJE --> START ');
5487 -- ========================= FND LOG ===========================
5488
5489 -- Get Originating Batch ID and Actual Flag
5490 open orig_bat;
5491 fetch orig_bat into l_je_batch_id, l_actual_flag, l_max_je_line_num;
5492 close orig_bat;
5493
5494 -- ========================= FND LOG ===========================
5495 psa_utils.debug_other_string(g_state_level,l_full_path, ' l_je_batch_id -> ' || l_je_batch_id);
5496 psa_utils.debug_other_string(g_state_level,l_full_path, ' l_actual_flag -> ' || l_actual_flag);
5497 -- ========================= FND LOG ===========================
5498
5499 -- Check whether we should avoid copying DFF information
5500 open avoid_copy_dff_attr;
5501 fetch avoid_copy_dff_attr into l_avoid_copying_attr;
5502 if (avoid_copy_dff_attr%notfound) then
5503 l_avoid_copying_attr := 'N';
5504 end if;
5505 close avoid_copy_dff_attr;
5506
5507 -- ========================= FND LOG ===========================
5508 psa_utils.debug_other_string(g_state_level,l_full_path, ' l_avoid_copying_attr -> ' || l_avoid_copying_attr);
5509 -- ========================= FND LOG ===========================
5510
5511 -- Create/Delete separate Actual Batch for the generated transactions
5512 -- if the Originating Batch is Budget/Encumbrance; else, append/delete
5513 -- the generated transactions to/from the Originating Actual Batch
5514
5515 if l_actual_flag <> 'A' then
5516 -- ========================= FND LOG ===========================
5517 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_fcmode -> ' || g_fcmode);
5518 -- ========================= FND LOG ===========================
5519
5520 if g_fcmode = 'U' then
5521 -- ========================= FND LOG ===========================
5522 psa_utils.debug_other_string(g_state_level,l_full_path, ' goto delete_separate_batch label ');
5523 -- ========================= FND LOG ===========================
5524 goto delete_separate_batch;
5525 else
5526 -- ========================= FND LOG ===========================
5527 psa_utils.debug_other_string(g_state_level,l_full_path, ' goto create_separate_batch label ');
5528 -- ========================= FND LOG ===========================
5529 goto create_separate_batch;
5530 end if;
5531
5532 end if;
5533
5534 -- Insert generated transactions in the packet into gl_je_lines for all
5535 -- headers of the originating batch
5536
5537 if g_fcmode <> 'U' then
5538
5539 if (l_avoid_copying_attr = 'Y') then
5540
5541 insert into gl_je_lines
5542 (je_header_id,
5543 je_line_num,
5544 last_update_date,
5545 last_updated_by,
5546 ledger_id,
5547 code_combination_id,
5548 period_name,
5549 effective_date,
5550 status,
5551 creation_date,
5552 created_by,
5553 entered_dr,
5554 entered_cr,
5555 accounted_dr,
5556 accounted_cr,
5557 tax_code,
5558 invoice_identifier,
5559 no1,
5560 ignore_rate_flag,
5561 reference_1,
5562 reference_10)
5563 select bp.je_header_id,
5564 l_max_je_line_num + 10 * rownum, -- bug 5139224
5565 sysdate,
5566 g_user_id,
5567 g_ledger_id,
5568 bp.code_combination_id,
5569 bp.period_name,
5570 jh.default_effective_date,
5571 'U',
5572 sysdate,
5573 g_user_id,
5574 bp.entered_dr,
5575 bp.entered_cr,
5576 bp.accounted_dr,
5577 bp.accounted_cr,
5578 ' ',
5579 ' ',
5580 ' ',
5581 'Y',
5582 BP.ussgl_link_to_parent_id,
5583 'glxfje() generated: ' || g_packet_id
5584 from gl_period_statuses ps,
5585 gl_je_headers jh,
5586 gl_bc_packets bp
5587 where ps.application_id = 101
5588 and ps.ledger_id = g_ledger_id
5589 and ps.period_name = bp.period_name
5590 and jh.je_header_id = bp.je_header_id
5591 and bp.packet_id = g_packet_id
5592 and bp.ussgl_link_to_parent_id is not null;
5593
5594 -- ========================= FND LOG ===========================
5595 psa_utils.debug_other_string(g_state_level,l_full_path,
5596 ' gl_je_lines for originating batch ' || sql%ROWCOUNT);
5597 -- ========================= FND LOG ===========================
5598
5599 else
5600
5601 INSERT INTO GL_JE_LINES
5602 (je_header_id,
5603 je_line_num,
5604 last_update_date,
5605 last_updated_by,
5606 ledger_id,
5607 code_combination_id,
5608 period_name,
5609 effective_date,
5610 status,
5611 creation_date,
5612 created_by,
5613 entered_dr,
5614 entered_cr,
5615 accounted_dr,
5616 accounted_cr,
5617 tax_code,
5618 invoice_identifier,
5619 no1,
5620 ignore_rate_flag,
5621 reference_1,
5622 reference_2,
5623 reference_3,
5624 reference_4,
5625 reference_5,
5626 reference_6,
5627 reference_7,
5628 reference_8,
5629 reference_9,
5630 reference_10,
5631 context,
5632 attribute1,
5633 attribute2,
5634 attribute3,
5635 attribute4,
5636 attribute5,
5637 attribute6,
5638 attribute7,
5639 attribute8,
5640 attribute9,
5641 attribute10)
5642 SELECT
5643 BP.je_header_id,
5644 JL.je_line_num + 10*rownum,
5645 SYSDATE,
5646 g_user_id,
5647 g_ledger_id,
5648 BP.code_combination_id,
5649 BP.period_name,
5650 JL.effective_date,
5651 'U',
5652 SYSDATE,
5653 g_user_id,
5654 BP.entered_dr,
5655 BP.entered_cr,
5656 BP.accounted_dr,
5657 BP.accounted_cr,
5658 ' ',
5659 ' ',
5660 ' ',
5661 'Y',
5662 BP.ussgl_link_to_parent_id,
5663 BP.reference2,
5664 BP.reference3,
5665 BP.reference4,
5666 BP.reference5,
5667 BP.reference6,
5668 BP.reference7,
5669 BP.reference8,
5670 BP.reference9,
5671 'glxfje() generated: ' || g_packet_id /* for unrsv only */,
5672 decode(JL1.context,JL1.context3,null,JL1.context),
5673 decode(JL1.context,JL1.context3,null,JL1.attribute1),
5674 decode(JL1.context,JL1.context3,null,JL1.attribute2),
5675 decode(JL1.context,JL1.context3,null,JL1.attribute3),
5676 decode(JL1.context,JL1.context3,null,JL1.attribute4),
5677 decode(JL1.context,JL1.context3,null,JL1.attribute5),
5678 decode(JL1.context,JL1.context3,null,JL1.attribute6),
5679 decode(JL1.context,JL1.context3,null,JL1.attribute7),
5680 decode(JL1.context,JL1.context3,null,JL1.attribute8),
5681 decode(JL1.context,JL1.context3,null,JL1.attribute9),
5682 decode(JL1.context,JL1.context3,null,JL1.attribute10)
5683 FROM
5684 GL_PERIOD_STATUSES PS,
5685 GL_JE_LINES JL,
5686 GL_JE_LINES JL1,
5687 GL_BC_PACKETS BP
5688 WHERE
5689 PS.application_id = 101
5690 AND PS.ledger_id = g_ledger_id
5691 AND PS.period_name = BP.period_name
5692 AND JL.je_header_id = BP.je_header_id
5693 AND JL.je_line_num = (SELECT max(JL1.je_line_num)
5694 FROM GL_JE_LINES JL1
5695 WHERE JL1.je_header_id = BP.je_header_id)
5696 AND BP.packet_id = g_packet_id
5697 AND BP.ussgl_link_to_parent_id IS NOT NULL
5698 AND JL1.je_header_id = BP.je_header_id
5699 AND JL1.je_line_num = BP.je_line_num;
5700
5701 -- ========================= FND LOG ===========================
5702 psa_utils.debug_other_string(g_state_level,l_full_path,
5703 ' Insert GL_JE_LINES -> ' || sql%ROWCOUNT);
5704 -- ========================= FND LOG ===========================
5705
5706 end if;
5707 else
5708
5709 -- For Unreservation, delete previously appended generated transactions
5710 -- from gl_je_lines
5711
5712 delete from gl_je_lines jl
5713 where jl.je_header_id in
5714 (
5715 select distinct bp.je_header_id
5716 from gl_bc_packets bp
5717 where bp.packet_id = g_packet_id
5718 and bp.ussgl_link_to_parent_id IS NOT NULL
5719 )
5720 and jl.reference_10 = 'glxfje() generated: ' || g_packet_id_ursvd;
5721
5722 -- ========================= FND LOG ===========================
5723 psa_utils.debug_other_string(g_state_level,l_full_path,
5724 ' delete gl_je_lines - Unreservation ' || sql%ROWCOUNT);
5725 -- ========================= FND LOG ===========================
5726
5727 end if;
5728
5729
5730 -- Update Control Total and Running Totals of all headers with generated
5731 -- transactions appended/deleted
5732
5733 update gl_je_headers jh
5734 set (jh.control_total,
5735 jh.running_total_dr,
5736 jh.running_total_cr,
5737 jh.running_total_accounted_dr,
5738 jh.running_total_accounted_cr) =
5739 (
5740 select decode(jh.control_total, null, null, jh.control_total +
5741 sum(nvl(bp.entered_dr, 0)) *
5742 decode(g_fcmode, 'U', -1, 1)),
5743 nvl(jh.running_total_dr, 0) + sum(nvl(bp.entered_dr, 0)) *
5744 decode(g_fcmode, 'U', -1, 1),
5745 nvl(jh.running_total_cr, 0) + sum(nvl(bp.entered_cr, 0)) *
5746 decode(g_fcmode, 'U', -1, 1),
5747 nvl(jh.running_total_accounted_dr, 0) +
5748 sum(nvl(bp.accounted_dr, 0)) *
5749 decode(g_fcmode, 'U', -1, 1),
5750 nvl(jh.running_total_accounted_cr, 0) +
5751 sum(nvl(bp.accounted_cr, 0)) *
5752 decode(g_fcmode, 'U', -1, 1)
5753 from gl_bc_packets bp
5754 where bp.packet_id = g_packet_id
5755 and bp.je_batch_id = jh.je_batch_id
5756 and bp.je_header_id = jh.je_header_id
5757 and bp.ussgl_link_to_parent_id is not null
5758 )
5759 where jh.je_header_id in
5760 (
5761 select distinct je_header_id
5762 from gl_bc_packets bp1
5763 where bp1.packet_id = g_packet_id
5764 and bp1.ussgl_link_to_parent_id is not null
5765 );
5766
5767 -- ========================= FND LOG ===========================
5768 psa_utils.debug_other_string(g_state_level,l_full_path,
5769 ' Update Control Total and Running Totals - gl_je_headers ' || SQL%ROWCOUNT);
5770 -- ========================= FND LOG ===========================
5771
5772
5773 -- Update Batch Control Total, Running Totals, Budgetary Control Status and
5774 -- Packet ID
5775
5776 update gl_je_batches jb
5777 set (jb.control_total,
5778 jb.running_total_dr,
5779 jb.running_total_cr,
5780 jb.running_total_accounted_dr,
5781 jb.running_total_accounted_cr,
5782 jb.budgetary_control_status,
5783 jb.packet_id) =
5784 (
5785 select decode(jb.control_total, null, null, jb.control_total +
5786 sum(nvl(bp.entered_dr, 0)) *
5787 decode(g_fcmode, 'U', -1, 1)),
5788 nvl(jb.running_total_dr, 0) + sum(nvl(bp.entered_dr, 0)) *
5789 decode(g_fcmode, 'U', -1, 1),
5790 nvl(jb.running_total_cr, 0) + sum(nvl(bp.entered_cr, 0)) *
5791 decode(g_fcmode, 'U', -1, 1),
5792 nvl(jb.running_total_accounted_dr, 0) +
5793 sum(nvl(bp.accounted_dr, 0)) * decode(g_fcmode, 'U', -1, 1),
5794 nvl(jb.running_total_accounted_cr, 0) +
5795 sum(nvl(bp.accounted_cr, 0)) * decode(g_fcmode, 'U', -1, 1),
5796 decode(g_fcmode, 'U', 'R', 'P'),
5797 decode(g_fcmode, 'U', null, jb.packet_id)
5798 from gl_bc_packets bp
5799 where bp.packet_id = g_packet_id
5800 and bp.je_batch_id = jb.je_batch_id
5801 and bp.ussgl_link_to_parent_id is not null
5802 )
5803 where jb.je_batch_id = l_je_batch_id;
5804
5805 -- ========================= FND LOG ===========================
5806 psa_utils.debug_other_string(g_state_level,l_full_path,
5807 ' Update gl_je_batches - Batch Control Total, Running Totals, ' ||
5808 ' Budgetary Control Status ' || SQL%ROWCOUNT);
5809 psa_utils.debug_other_string(g_state_level,l_full_path, ' goto normal_exit label ');
5810 -- ========================= FND LOG ===========================
5811
5812 -- Invoke GL API to fix the GL_JE_SEGMENT_VALUES table.
5813 -- We invoke this API with batch_id parameter so that it works with both inserts/deletes
5814
5815 l_seg_val_ret_code := gl_je_segment_values_pkg.insert_batch_segment_values(l_je_batch_id);
5816
5817 -- Exit since Originating Batch is Actual
5818 goto normal_exit;
5819
5820 <<create_separate_batch>>
5821
5822 -- ========================= FND LOG ===========================
5823 psa_utils.debug_other_string(g_state_level,l_full_path, ' Reached create_separate_batch label ');
5824 -- ========================= FND LOG ===========================
5825
5826 -- Get new Batch ID from Sequence
5827 open batch_id;
5828 fetch batch_id into l_gen_batch_id;
5829 close batch_id;
5830
5831 open enable_approval;
5832 fetch enable_approval into l_enable_app;
5833 close enable_approval;
5834
5835 -- ========================= FND LOG ===========================
5836 psa_utils.debug_other_string(g_state_level,l_full_path, ' l_gen_batch_id -> '|| l_gen_batch_id);
5837 psa_utils.debug_other_string(g_state_level,l_full_path, ' l_enable_app -> '|| l_enable_app.enable_je_approval_flag);
5838 -- ========================= FND LOG ===========================
5839
5840 if l_enable_app.enable_je_approval_flag = 'Y' then
5841
5842 open je_source(l_je_batch_id);
5843 fetch je_source into l_je_source;
5844 close je_source;
5845
5846 -- ========================= FND LOG ===========================
5847 psa_utils.debug_other_string(g_state_level,l_full_path, ' l_je_source -> '|| l_je_source.je_source);
5848 -- ========================= FND LOG ===========================
5849
5850 open je_approval(l_je_source.je_source);
5851 fetch je_approval into l_je_approval;
5852 close je_approval;
5853
5854 -- ========================= FND LOG ===========================
5855 psa_utils.debug_other_string(g_state_level,l_full_path, ' l_je_approval -> '|| l_je_approval.journal_approval_flag);
5856 -- ========================= FND LOG ===========================
5857
5858 if l_je_approval.journal_approval_flag = 'Y' then
5859 l_approval_status_code := 'R';
5860 else
5861 l_approval_status_code := 'Z';
5862 end if;
5863
5864 else
5865 l_approval_status_code := 'Z';
5866 end if;
5867
5868 -- ========================= FND LOG ===========================
5869 psa_utils.debug_other_string(g_state_level,l_full_path,
5870 ' l_approval_status_code -> '|| l_approval_status_code);
5871 -- ========================= FND LOG ===========================
5872
5873 -- Create new Actual Batch for the Generated Transactions
5874 insert into gl_je_batches
5875 (je_batch_id,
5876 last_update_date,
5877 last_updated_by,
5878 set_of_books_id_11i,
5879 name,
5880 status,
5881 status_verified,
5882 actual_flag,
5883 default_effective_date,
5884 creation_date,
5885 created_by,
5886 default_period_name,
5887 date_created,
5888 description,
5889 running_total_dr,
5890 running_total_cr,
5891 running_total_accounted_dr,
5892 running_total_accounted_cr,
5893 budgetary_control_status,
5894 packet_id,
5895 average_journal_flag,
5896 approval_status_code,
5897 chart_of_accounts_id,
5898 period_set_name,
5899 accounted_period_type)
5900 select l_gen_batch_id,
5901 sysdate,
5902 g_user_id,
5903 g_ledger_id,
5904 substrb('CJE: ' || min(jb.name) ||' '||
5905 to_char(sysdate)||
5906 to_char(sysdate,' HH24:MI:SS: ')||
5907 'A', 1, 100),
5908 'U',
5909 'N',
5910 'A',
5911 min(jb.default_effective_date),
5912 sysdate,
5913 g_user_id,
5914 min(bp.period_name),
5915 sysdate,
5916 decode(min(jb.description), null, null,
5917 substrb('CJE: ' || min(jb.description), 1, 240)),
5918 sum(nvl(bp.entered_dr, 0)),
5919 sum(nvl(bp.entered_cr, 0)),
5920 sum(nvl(bp.accounted_dr, 0)),
5921 sum(nvl(bp.accounted_cr, 0)),
5922 'P',
5923 null, /* For Disabling Unreservation on Generated Batches */
5924 min(jb.average_journal_flag),
5925 l_approval_status_code,
5926 min(jb.chart_of_accounts_id),
5927 min(jb.period_set_name),
5928 min(jb.accounted_period_type)
5929 from gl_period_statuses ps,
5930 gl_bc_packets bp,
5931 gl_je_batches jb
5932 where ps.application_id = 101
5933 and ps.ledger_id = g_ledger_id
5934 and ps.period_name = bp.period_name
5935 and bp.packet_id = g_packet_id
5936 and bp.ussgl_link_to_parent_id is not null
5937 and jb.je_batch_id = l_je_batch_id;
5938
5939
5940 -- ========================= FND LOG ===========================
5941 psa_utils.debug_other_string(g_state_level,l_full_path,
5942 ' Creating new actual bacth - gl_je_batches -> '|| SQL%ROWCOUNT);
5943 -- ========================= FND LOG ===========================
5944
5945
5946 -- ========================= FND LOG ===========================
5947 psa_utils.debug_other_string(g_state_level,l_full_path, ' Calling glurevd ');
5948 -- ========================= FND LOG ===========================
5949
5950 DECLARE
5951
5952 CURSOR batch_sources IS
5953 SELECT je_header_id, je_category, je_source, period_name
5954 FROM gl_je_headers
5955 WHERE je_batch_id = l_je_batch_id;
5956
5957 BEGIN
5958 FOR x IN batch_sources
5959 LOOP
5960
5961 -- ========================= FND LOG ===========================
5962 psa_utils.debug_other_string(g_state_level,l_full_path, ' x.je_header_id -> '|| x.je_header_id);
5963 psa_utils.debug_other_string(g_state_level,l_full_path, ' x.je_category -> '|| x.je_category);
5964 psa_utils.debug_other_string(g_state_level,l_full_path, ' x.je_source -> '|| x.je_source);
5965 psa_utils.debug_other_string(g_state_level,l_full_path, ' x.period_name -> '|| x.period_name);
5966 -- ========================= FND LOG ===========================
5967
5968 IF NOT ( glurevd(p_ledger_id => g_ledger_id,
5969 p_je_category => x.je_category,
5970 p_je_source => x.je_source,
5971 p_je_period => x.period_name,
5972 p_je_date => sysdate,
5973 x_reversal_method => l_reversal_method,
5974 p_balance_type => 'A')) THEN
5975
5976 -- ========================= FND LOG ===========================
5977 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN -> FALSE ');
5978 -- ========================= FND LOG ===========================
5979 g_debug := g_debug||' GLXFJE Failed : glurevd returned FALSE';
5980 return (FALSE);
5981 END IF;
5982
5983 -- Create associated headers for the new Actual Batch
5984 insert into gl_je_headers
5985 (je_header_id,
5986 last_update_date,
5987 last_updated_by,
5988 ledger_id,
5989 je_category,
5990 je_source,
5991 period_name,
5992 name,
5993 currency_code,
5994 status,
5995 date_created,
5996 accrual_rev_flag,
5997 multi_bal_seg_flag,
5998 actual_flag,
5999 conversion_flag,
6000 default_effective_date,
6001 creation_date,
6002 created_by,
6003 je_batch_id,
6004 description,
6005 currency_conversion_rate,
6006 currency_conversion_type,
6007 currency_conversion_date,
6008 attribute1,
6009 accrual_rev_change_sign_flag,
6010 tax_status_code)
6011 select gl_je_headers_s.nextval,
6012 sysdate,
6013 g_user_id,
6014 g_ledger_id,
6015 jh.je_category,
6016 jh.je_source,
6017 jh.period_name,
6018 substrb('CJE: ' || jh.name ||' '||
6019 to_char(sysdate)||
6020 to_char(sysdate,' HH24:MI:SS'),1,100),
6021 jh.currency_code,
6022 'U',
6023 sysdate,
6024 'N',
6025 'N',
6026 'A',
6027 'N',
6028 jh.default_effective_date,
6029 sysdate,
6030 g_user_id,
6031 l_gen_batch_id,
6032 decode(jh.description, null, null,
6033 substrb('CJE: ' || jh.description, 1, 240)),
6034 1,
6035 'User',
6036 sysdate,
6037 to_char(jh.je_header_id),
6038 l_reversal_method,
6039 'N'
6040 from gl_je_headers jh
6041 where jh.je_batch_id = l_je_batch_id
6042 and jh.je_header_id = x.je_header_id
6043 and exists
6044 (
6045 select 'JE headers with associated generated transactions'
6046 from gl_bc_packets bp
6047 where bp.packet_id = g_packet_id
6048 and bp.je_batch_id = l_je_batch_id
6049 and bp.je_header_id = jh.je_header_id
6050 and bp.ussgl_link_to_parent_id is not null
6051 );
6052
6053
6054 -- ========================= FND LOG ===========================
6055 psa_utils.debug_other_string(g_state_level,l_full_path,
6056 ' Insert gl_je_headers - Headers for Actual Batches ' || SQL%ROWCOUNT);
6057 -- ========================= FND LOG ===========================
6058 END LOOP;
6059 END;
6060
6061 -- Update running totals of associated headers
6062
6063 update gl_je_headers jh
6064 set (jh.running_total_dr,
6065 jh.running_total_cr,
6066 jh.running_total_accounted_dr,
6067 jh.running_total_accounted_cr) =
6068 (
6069 select sum(nvl(bp.entered_dr, 0)),
6070 sum(nvl(bp.entered_cr, 0)),
6071 sum(nvl(bp.accounted_dr, 0)),
6072 sum(nvl(bp.accounted_cr, 0))
6073 from gl_bc_packets bp
6074 where bp.packet_id = g_packet_id
6075 and bp.je_batch_id = l_je_batch_id
6076 and bp.je_header_id = to_number(jh.attribute1)
6077 and bp.ussgl_link_to_parent_id is not null
6078 )
6079 where JH.je_batch_id = l_gen_batch_id;
6080
6081 -- ========================= FND LOG ===========================
6082 psa_utils.debug_other_string(g_state_level,l_full_path,
6083 ' update gl_je_headers - running totals - ' || SQL%ROWCOUNT);
6084 -- ========================= FND LOG ===========================
6085
6086 -- Insert generated transactions in packet into gl_je_lines
6087 if (l_avoid_copying_attr = 'Y') then
6088
6089 insert into gl_je_lines
6090 (je_header_id,
6091 je_line_num,
6092 last_update_date,
6093 last_updated_by,
6094 ledger_id,
6095 code_combination_id,
6096 period_name,
6097 effective_date,
6098 status,
6099 creation_date,
6100 created_by,
6101 entered_dr,
6102 entered_cr,
6103 accounted_dr,
6104 accounted_cr,
6105 tax_code,
6106 invoice_identifier,
6107 no1,
6108 ignore_rate_flag,
6109 reference_10)
6110 select jh.je_header_id,
6111 10 * row_number() over (partition by jh.je_header_id
6112 order by jh.je_header_id),
6113 sysdate,
6114 g_user_id,
6115 g_ledger_id,
6116 bp.code_combination_id,
6117 bp.period_name,
6118 jh.default_effective_date,
6119 'U',
6120 sysdate,
6121 g_user_id,
6122 bp.entered_dr,
6123 bp.entered_cr,
6124 bp.accounted_dr,
6125 bp.accounted_cr,
6126 ' ',
6127 ' ',
6128 ' ',
6129 'Y',
6130 'glxfje() generated: ' || g_packet_id
6131 from gl_je_headers jh,
6132 gl_bc_packets bp
6133 where jh.je_batch_id = l_gen_batch_id
6134 and jh.attribute1 = to_char(bp.je_header_id)
6135 and bp.packet_id = g_packet_id
6136 and bp.ussgl_link_to_parent_id is not null;
6137
6138 else
6139
6140 INSERT INTO GL_JE_LINES
6141 (je_header_id,
6142 je_line_num,
6143 last_update_date,
6144 last_updated_by,
6145 ledger_id,
6146 code_combination_id,
6147 period_name,
6148 effective_date,
6149 status,
6150 creation_date,
6151 created_by,
6152 entered_dr,
6153 entered_cr,
6154 accounted_dr,
6155 accounted_cr,
6156 tax_code,
6157 invoice_identifier,
6158 no1,
6159 ignore_rate_flag,
6160 reference_10,
6161 context,
6162 attribute1,
6163 attribute2,
6164 attribute3,
6165 attribute4,
6166 attribute5,
6167 attribute6,
6168 attribute7,
6169 attribute8,
6170 attribute9,
6171 attribute10)
6172 SELECT
6173 min(JH.je_header_id),
6174 10*count(BP1.rowid),
6175 SYSDATE,
6176 g_user_id,
6177 g_ledger_id,
6178 min(BP.code_combination_id),
6179 min(BP.period_name),
6180 min(JH.default_effective_date),
6181 'U',
6182 SYSDATE,
6183 g_ledger_id,
6184 min(BP.entered_dr),
6185 min(BP.entered_cr),
6186 min(BP.accounted_dr),
6187 min(BP.accounted_cr),
6188 ' ',
6189 ' ',
6190 ' ',
6191 'Y',
6192 'glxfje() generated: ' || g_packet_id, /* for unrsv only */
6193 decode(min(JL.context),min(JL.context3),null,min(JL.context)),
6194 decode(min(JL.context),min(JL.context3),null,min(JL.attribute1)),
6195 decode(min(JL.context),min(JL.context3),null,min(JL.attribute2)),
6196 decode(min(JL.context),min(JL.context3),null,min(JL.attribute3)),
6197 decode(min(JL.context),min(JL.context3),null,min(JL.attribute4)),
6198 decode(min(JL.context),min(JL.context3),null,min(JL.attribute5)),
6199 decode(min(JL.context),min(JL.context3),null,min(JL.attribute6)),
6200 decode(min(JL.context),min(JL.context3),null,min(JL.attribute7)),
6201 decode(min(JL.context),min(JL.context3),null,min(JL.attribute8)),
6202 decode(min(JL.context),min(JL.context3),null,min(JL.attribute9)),
6203 decode(min(JL.context),min(JL.context3),null,min(JL.attribute10))
6204 FROM
6205 GL_JE_HEADERS JH,
6206 GL_BC_PACKETS BP1,
6207 GL_BC_PACKETS BP,
6208 GL_JE_LINES JL
6209 WHERE
6210 JH.je_batch_id = l_gen_batch_id
6211 AND JH.attribute1 = to_char(BP.je_header_id)
6212 AND BP1.packet_id = BP.packet_id
6213 AND BP1.je_batch_id = BP.je_batch_id
6214 AND BP1.je_header_id = BP.je_header_id
6215 AND BP1.rowid <= BP.rowid
6216 AND BP1.ussgl_link_to_parent_id IS NOT NULL
6217 AND BP.packet_id = g_packet_id
6218 AND BP.ussgl_link_to_parent_id IS NOT NULL
6219 AND JL.je_header_id = BP.je_header_id
6220 AND JL.je_line_num = BP.je_line_num
6221 GROUP BY BP.rowid;
6222
6223 end if;
6224
6225 -- ========================= FND LOG ===========================
6226 psa_utils.debug_other_string(g_state_level,l_full_path,
6227 ' Insert gl_je_lines - ' || SQL%ROWCOUNT);
6228 -- ========================= FND LOG ===========================
6229
6230
6231 -- Update je_batch_id of all associated generated transactions from the
6232 -- ID of the Originating Batch to that of the newly created batch so that
6233 -- posting deletes only these packet rows
6234
6235 update gl_bc_packets bp
6236 set bp.je_batch_id = l_gen_batch_id
6237 where bp.packet_id = g_packet_id
6238 and bp.ussgl_link_to_parent_id is not null;
6239
6240 -- ========================= FND LOG ===========================
6241 psa_utils.debug_other_string(g_state_level,l_full_path,
6242 ' update gl_bc_packets - je_bacth_id - ' || SQL%ROWCOUNT);
6243 -- ========================= FND LOG ===========================
6244
6245 -- Clean up attribute1 in gl_je_headers (contains header id of the
6246 -- originating line)
6247
6248 update gl_je_headers jh
6249 set jh.attribute1 = null
6250 where jh.je_batch_id = l_gen_batch_id;
6251
6252 -- ========================= FND LOG ===========================
6253 psa_utils.debug_other_string(g_state_level,l_full_path,
6254 ' update gl_je_headers -> ' || SQL%ROWCOUNT);
6255 psa_utils.debug_other_string(g_state_level,l_full_path,
6256 ' goto normal_exit label ');
6257 -- ========================= FND LOG ===========================
6258
6259 -- Invoke GL API to fix the GL_JE_SEGMENT_VALUES table.
6260
6261 l_seg_val_ret_code := gl_je_segment_values_pkg.insert_batch_segment_values(l_gen_batch_id);
6262
6263 goto normal_exit;
6264
6265 <<delete_separate_batch>>
6266 -- ========================= FND LOG ===========================
6267 psa_utils.debug_other_string(g_state_level,l_full_path,
6268 ' Reached delete_seperate_batch label ');
6269 -- ========================= FND LOG ===========================
6270
6271 -- Delete all previously created associated generated transactions from
6272 -- gl_je_lines
6273
6274 delete from gl_je_lines jl
6275 where jl.je_header_id in
6276 (
6277 select distinct jh.je_header_id
6278 from gl_je_headers jh,
6279 gl_bc_packets bp
6280 where jh.je_batch_id = bp.je_batch_id
6281 and bp.packet_id = g_packet_id
6282 and bp.ussgl_link_to_parent_id is not null
6283 )
6284 and jl.reference_10 = 'glxfje() generated: ' || g_packet_id_ursvd;
6285
6286 -- ========================= FND LOG ===========================
6287 psa_utils.debug_other_string(g_state_level,l_full_path,
6288 ' Delete gl_je_lines - ' || SQL%ROWCOUNT);
6289 -- ========================= FND LOG ===========================
6290
6291 -- Delete all associated headers of the generated transactions
6292
6293 delete from gl_je_headers jh
6294 where jh.je_batch_id in
6295 (
6296 select distinct bp.je_batch_id
6297 from gl_bc_packets bp
6298 where bp.packet_id = g_packet_id
6299 and bp.ussgl_link_to_parent_id is not null
6300 );
6301
6302 -- ========================= FND LOG ===========================
6303 psa_utils.debug_other_string(g_state_level,l_full_path,
6304 ' Delete gl_je_headers - ' || SQL%ROWCOUNT);
6305 -- ========================= FND LOG ===========================
6306
6307 -- Delete the associated batch of the generated transactions
6308
6309 FOR x IN generated_bat
6310 LOOP
6311 delete from gl_je_batches jb
6312 where jb.je_batch_id = x.je_batch_id;
6313
6314 -- ========================= FND LOG ===========================
6315 psa_utils.debug_other_string(g_state_level,l_full_path,
6316 ' Delete gl_je_batches - ' || SQL%ROWCOUNT);
6317 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN - TRUE ');
6318 -- ========================= FND LOG ===========================
6319
6320 -- Invoke the GL API to fix the GL_JE_SEGMENT_VALUES table
6321
6322 l_seg_val_ret_code := gl_je_segment_values_pkg.insert_batch_segment_values(x.je_batch_id);
6323 END LOOP;
6324
6325
6326 return(TRUE);
6327
6328 <<normal_exit>>
6329 -- ========================= FND LOG ===========================
6330 psa_utils.debug_other_string(g_state_level,l_full_path,
6331 ' Reached normal_exit label');
6332 -- ========================= FND LOG ===========================
6333
6334 if NOT g_conc_flag AND l_actual_flag = 'A' then
6335 COMMIT;
6336 g_requery_flag := TRUE;
6337 end if;
6338
6339 -- ========================= FND LOG ===========================
6340 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN - TRUE ');
6341 -- ========================= FND LOG ===========================
6342 return(TRUE);
6343
6344
6345 EXCEPTION
6346
6347 WHEN OTHERS THEN
6348
6349 if orig_bat%ISOPEN then
6350 close orig_bat;
6351 end if;
6352
6353 if batch_id%ISOPEN then
6354 close batch_id;
6355 end if;
6356
6357 message_token('PROCEDURE', 'Funds Checker');
6358 message_token('EVENT', SQLERRM);
6359 add_message('SQLGL', 'GL_UNHANDLED_EXCEPTION');
6360
6361 -- ========================= FND LOG ===========================
6362 psa_utils.debug_other_string(g_excep_level,l_full_path, ' EXCEPTION WHEN OTHERS ' || SQLERRM);
6363 psa_utils.debug_other_string(g_excep_level,l_full_path, ' RETURN - FALSE ');
6364 -- ========================= FND LOG ===========================
6365 g_debug := g_debug||' GLXFJE Failed : '||SQLERRM;
6366 return(FALSE);
6367
6368 END glxfje;
6369
6370 /* ============================= GLXFPP ============================= */
6371
6372 -- Purge Packets after Funds Check
6373
6374 -- This Module provides a way for any external Funds Check implementation
6375 -- to rollback Funds Reserved after the Funds Checker call. This must be
6376 -- called before any commit that would otherwise confirm the final Funds
6377 -- Check Status of the packet
6378
6379 -- This Module deletes all transaction lines of a packet in gl_bc_packets and
6380 -- the associated Arrival Order record in gl_bc_packet_arrival_order
6381
6382 -- This Module also deletes the corresponding records for a packet being
6383 -- Unreserved
6384
6385 -- This Function is invoked by any Module that needs to purge all packet
6386 -- related information after the Funds Checker call
6387
6388
6389 -- Parameters :
6390 -- p_packetid : Packet ID
6391 -- p_packetid_ursvd : Unreservation Packet ID. Defaults to 0
6392
6393 PROCEDURE glxfpp(p_packetid IN NUMBER,
6394 p_packetid_ursvd IN NUMBER) IS
6395
6396 -- ========================= FND LOG ===========================
6397 l_full_path VARCHAR2(100);
6398 -- ========================= FND LOG ===========================
6399
6400 BEGIN
6401
6402 l_full_path := g_path || 'glxfpp1';
6403
6404 -- ========================= FND LOG ===========================
6405 psa_utils.debug_other_string(g_state_level,l_full_path, ' GLXFPP1 --> START ');
6406 -- ========================= FND LOG ===========================
6407
6408 -- Delete Packet Transactions
6409 delete from gl_bc_packets bp
6410 where bp.packet_id in (p_packetid, p_packetid_ursvd);
6411
6412 -- ========================= FND LOG ===========================
6413 psa_utils.debug_other_string(g_state_level,l_full_path,
6414 ' delete from gl_bc_packets ' || SQL%ROWCOUNT);
6415 -- ========================= FND LOG ===========================
6416
6417 -- Delete Packet Arrival Order Record
6418 delete from gl_bc_packet_arrival_order ao
6419 where ao.packet_id in (p_packetid, p_packetid_ursvd);
6420
6421 -- ========================= FND LOG ===========================
6422 psa_utils.debug_other_string(g_state_level,l_full_path,
6423 ' delete from gl_bc_packet_arrival_order ' || SQL%ROWCOUNT);
6424 -- ========================= FND LOG ===========================
6425
6426 EXCEPTION
6427
6428 WHEN OTHERS THEN
6429
6430 message_token('PROCEDURE', 'Funds Checker');
6431 message_token('EVENT', SQLERRM);
6432 add_message('SQLGL', 'GL_UNHANDLED_EXCEPTION');
6433
6434 -- ========================= FND LOG ===========================
6435 psa_utils.debug_other_string(g_excep_level,l_full_path, ' EXCEPTION WHEN OTHERS ' || SQLERRM);
6436 -- ========================= FND LOG ===========================
6437
6438 END glxfpp;
6439
6440 PROCEDURE glxfpp(p_eventid IN NUMBER) IS
6441
6442 -- ========================= FND LOG ===========================
6443 l_full_path VARCHAR2(100);
6444 -- ========================= FND LOG ===========================
6445
6446 BEGIN
6447
6448 l_full_path := g_path || 'glxfpp2';
6449
6450 -- ========================= FND LOG ===========================
6451 psa_utils.debug_other_string(g_state_level,l_full_path, ' GLXFPP2 --> START ');
6452 -- ========================= FND LOG ===========================
6453
6454 -- Delete Packet Transactions
6455 delete from gl_bc_packets bp
6456 where bp.event_id = p_eventid;
6457
6458 -- ========================= FND LOG ===========================
6459 psa_utils.debug_other_string(g_state_level,l_full_path,
6460 ' delete from gl_bc_packets ' || SQL%ROWCOUNT);
6461 -- ========================= FND LOG ===========================
6462
6463 -- Delete Packet Arrival Order Record
6464 delete from gl_bc_packet_arrival_order ao
6465 where ao.packet_id in (select packet_id
6466 from gl_bc_packets
6467 where event_id = p_eventid);
6468
6469 -- ========================= FND LOG ===========================
6470 psa_utils.debug_other_string(g_state_level,l_full_path,
6471 ' delete from gl_bc_packet_arrival_order ' || SQL%ROWCOUNT);
6472 -- ========================= FND LOG ===========================
6473
6474 -- Delete History Record
6475 delete from gl_bc_packets_hists bp
6476 where bp.event_id = p_eventid;
6477
6478 -- ========================= FND LOG ===========================
6479 psa_utils.debug_other_string(g_state_level,l_full_path,
6480 ' delete from gl_bc_packets_hists ' || SQL%ROWCOUNT);
6481 -- ========================= FND LOG ===========================
6482
6483 EXCEPTION
6484
6485 WHEN OTHERS THEN
6486
6487 message_token('PROCEDURE', 'Funds Checker');
6488 message_token('EVENT', SQLERRM);
6489 add_message('SQLGL', 'GL_UNHANDLED_EXCEPTION');
6490
6491 -- ========================= FND LOG ===========================
6492 psa_utils.debug_other_string(g_excep_level,l_full_path, ' EXCEPTION WHEN OTHERS ' || SQLERRM);
6493 -- ========================= FND LOG ===========================
6494
6495 END glxfpp;
6496
6497 /* ============================ GLXFUF ============================ */
6498
6499 -- Update Status Code for Transactions to Fatal
6500
6501 -- Updates Status Code for all transactions in the Packet to 'T'; it also
6502 -- updates affect_funds_flag in gl_bc_packet_arrival_order to 'N' so that
6503 -- the available Funds calculation of packets arriving later is not affected
6504 -- in case an irrecoverable error halts Funds Check. SQLs for updating the
6505 -- columns are not guaranteed to succeed in many drastic cases. However, this
6506 -- step tries to ensure that the current packet does not affect the Funds
6507 -- Available calculation for packets arriving later
6508
6509 -- The final cleanup is done by the Sweeper program, which deletes all packets
6510 -- with Status 'T', as well as all packets with Status 'P' (Pending) which are
6511 -- older than a specific (relatively long) time interval. This remedies for
6512 -- cases where the update could not be done in this Module
6513
6514 FUNCTION glxfuf RETURN BOOLEAN IS
6515 -- ========================= FND LOG ===========================
6516 l_full_path VARCHAR2(100);
6517 -- ========================= FND LOG ===========================
6518 BEGIN
6519
6520 l_full_path := g_path || 'glxfuf';
6521
6522 -- ========================= FND LOG ===========================
6523 psa_utils.debug_other_string(g_state_level,l_full_path, ' glxfuf -> START ');
6524 -- ========================= FND LOG ===========================
6525
6526 -- Update Status Code for the Packet Transactions
6527 update gl_bc_packets bp
6528 set bp.status_code = 'T'
6529 where bp.packet_id = g_packet_id;
6530
6531 -- ========================= FND LOG ===========================
6532 psa_utils.debug_other_string(g_state_level,l_full_path,
6533 ' g_packet_id -> ' || g_packet_id );
6534 psa_utils.debug_other_string(g_state_level,l_full_path,
6535 ' update gl_bc_packets with T -> ' || SQL%ROWCOUNT );
6536 -- ========================= FND LOG ===========================
6537
6538 -- Update Affect Funds Flag
6539 update gl_bc_packet_arrival_order ao
6540 set ao.affect_funds_flag = 'N'
6541 where ao.packet_id = g_packet_id;
6542
6543 -- ========================= FND LOG ===========================
6544 psa_utils.debug_other_string(g_state_level,l_full_path,
6545 ' update gl_bc_packet_arrival_order to N -> ' || SQL%ROWCOUNT );
6546 -- ========================= FND LOG ===========================
6547
6548 if not glrchk('Z') then
6549 -- ========================= FND LOG ===========================
6550 psa_utils.debug_other_string(g_state_level,l_full_path, ' glrchk(Z) -> FALSE' );
6551 -- ========================= FND LOG ===========================
6552 null;
6553 end if;
6554
6555 -- ========================= FND LOG ===========================
6556 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN --> TRUE' );
6557 -- ========================= FND LOG ===========================
6558 return(TRUE);
6559
6560 EXCEPTION
6561
6562 WHEN OTHERS THEN
6563
6564 message_token('PROCEDURE', 'Funds Checker');
6565 message_token('EVENT', SQLERRM);
6566 add_message('SQLGL', 'GL_UNHANDLED_EXCEPTION');
6567
6568 -- ========================= FND LOG ===========================
6569 psa_utils.debug_other_string(g_excep_level,l_full_path, ' EXCEPTION WHEN OTHERS ' || SQLERRM );
6570 psa_utils.debug_other_string(g_excep_level,l_full_path, ' RETURN --> FALSE' );
6571 -- ========================= FND LOG ===========================
6572 g_debug := g_debug||' GLXFUF Failed : '||SQLERRM;
6573 return(FALSE);
6574
6575 END glxfuf;
6576
6577 /* =============================== MESSAGE_TOKEN ======================= */
6578
6579 -- Add Token and Value to the Message Token array
6580
6581 PROCEDURE message_token(tokname IN VARCHAR2,
6582 tokval IN VARCHAR2) IS
6583
6584 l_full_path VARCHAR2(100);
6585
6586 BEGIN
6587
6588 l_full_path := g_path||'Message_Token';
6589
6590 if g_no_msg_tokens is null then
6591 g_no_msg_tokens := 1;
6592 else
6593 g_no_msg_tokens := g_no_msg_tokens + 1;
6594 end if;
6595
6596 -- ========================= FND LOG ===========================
6597 psa_utils.debug_other_string(g_excep_level,l_full_path, ' g_no_msg_tokens -> ' || g_no_msg_tokens );
6598 -- ========================= FND LOG ===========================
6599
6600 msg_tok_names(g_no_msg_tokens) := tokname;
6601 msg_tok_val(g_no_msg_tokens) := tokval;
6602
6603 END message_token;
6604
6605 /* =========================== ADD_MESSAGE ============================== */
6606
6607 -- Sets the Message Stack
6608
6609 PROCEDURE add_message(appname IN VARCHAR2,
6610 msgname IN VARCHAR2) IS
6611
6612 i BINARY_INTEGER;
6613 l_full_path VARCHAR2(100);
6614
6615 BEGIN
6616
6617 l_full_path := g_path||'Add_Message';
6618
6619 if ((appname is not null) and
6620 (msgname is not null)) then
6621
6622 FND_MESSAGE.SET_NAME(appname, msgname);
6623
6624 if g_no_msg_tokens is not null then
6625
6626 for i in 1..g_no_msg_tokens loop
6627 FND_MESSAGE.SET_TOKEN(msg_tok_names(i), msg_tok_val(i));
6628 end loop;
6629
6630 end if;
6631
6632 end if;
6633
6634 -- Clear Message Token stack
6635 g_no_msg_tokens := 0;
6636
6637 -- ========================= FND LOG ===========================
6638 psa_utils.debug_other_string(g_excep_level,l_full_path, ' g_no_msg_tokens -> ' || g_no_msg_tokens );
6639 -- ========================= FND LOG ===========================
6640
6641
6642 END add_message;
6643
6644
6645 /* ========================== FV_PREPAY_PKG ========================== */
6646
6647 FUNCTION fv_prepay_pkg RETURN BOOLEAN IS
6648
6649 -- Bug 3861686, added subquery to get the owner of the package.
6650
6651 CURSOR c_fv_prepay_pkg is
6652 SELECT DISTINCT 'Y' status
6653 FROM ALL_OBJECTS
6654 WHERE object_name = 'FV_AP_PREPAY_PKG'
6655 AND object_type = 'PACKAGE'
6656 AND owner = (SELECT oracle_username
6657 FROM fnd_oracle_userid
6658 WHERE read_only_flag = 'U')
6659 AND status = 'VALID';
6660
6661 CURSOR c_packet_count(c_packet_id IN NUMBER) is
6662 SELECT count(*) pkt_cnt
6663 FROM gl_bc_packets
6664 WHERE packet_id = c_packet_id;
6665
6666 cursor c_batch_id (c_packet_id IN NUMBER) is
6667 SELECT 'Y' batch_id
6668 FROM GL_BC_PACKETS
6669 WHERE packet_id = c_packet_id
6670 AND je_batch_id IS NOT NULL
6671 AND rownum = 1;
6672
6673 l_fv_prepay_pkg c_fv_prepay_pkg%rowtype;
6674 l_packet_count c_packet_count%rowtype;
6675 l_batch_id c_batch_id%rowtype;
6676
6677 fv_prepay_stmt VARCHAR2(2000);
6678 p_packet_id gl_bc_packets.packet_id%type;
6679 p_status NUMBER(15);
6680 l_full_path VARCHAR2(100);
6681
6682 BEGIN
6683
6684 l_full_path := g_path||'Fv_Prepay_pkg';
6685 if g_fv_prepay_prof then
6686
6687 p_packet_id := g_packet_id;
6688
6689 if g_fcmode IN ( 'C', 'R' ) then
6690
6691 open c_fv_prepay_pkg;
6692 fetch c_fv_prepay_pkg
6693 into l_fv_prepay_pkg;
6694 close c_fv_prepay_pkg;
6695
6696 -- ========================= FND LOG ===========================
6697 psa_utils.debug_other_string(g_excep_level,l_full_path, ' l_fv_prepay_pkg.status -> ' || l_fv_prepay_pkg.status );
6698 -- ========================= FND LOG ===========================
6699
6700
6701 if l_fv_prepay_pkg.status = 'Y' then
6702
6703 open c_packet_count(p_packet_id);
6704 fetch c_packet_count
6705 into l_packet_count;
6706 close c_packet_count;
6707
6708 if l_packet_count.pkt_cnt IS NOT NULL then
6709
6710 open c_batch_id(p_packet_id);
6711 fetch c_batch_id
6712 into l_batch_id;
6713 close c_batch_id;
6714
6715 if l_batch_id.batch_id IS NULL then
6716
6717 fv_prepay_stmt :=
6718 'BEGIN FV_AP_PREPAY_PKG.CREATE_PREPAY_LINES(:p_packet_id, :p_status); END;';
6719
6720 execute immediate fv_prepay_stmt USING IN p_packet_id, OUT p_status;
6721
6722 -- 0 : Success 1 : Failure
6723
6724 if p_status = 1 then
6725
6726 message_token('PROCEDURE', 'FV_AP_PREPAY_PKG.CREATE_PREPAY_LINES Returned Failure');
6727 message_token('EVENT', SQLERRM);
6728 add_message('SQLGL', 'GL_UNHANDLED_EXCEPTION');
6729 g_debug := g_debug||' FV_PREPAY_PKG Failed : FV_AP_PREPAY_PKG.CREATE_PREPAY_LINES
6730 Returned Failure';
6731 return(FALSE);
6732
6733 end if;
6734 end if;
6735 end if;
6736 end if;
6737 end if;
6738 end if;
6739
6740 RETURN TRUE;
6741
6742 EXCEPTION
6743 WHEN OTHERS THEN
6744 message_token('PROCEDURE', 'FV_AP_PREPAY_PKG.CREATE_PREPAY_LINES Returned Failure');
6745 message_token('EVENT', SQLERRM);
6746 add_message('SQLGL', 'GL_UNHANDLED_EXCEPTION');
6747
6748 -- ========================= FND LOG ===========================
6749 psa_utils.debug_other_string(g_excep_level,l_full_path, ' EXCEPTION WHEN OTHERS ' || SQLERRM);
6750 psa_utils.debug_other_string(g_excep_level,l_full_path, ' RETURN FALSE');
6751 -- ========================= FND LOG ===========================
6752
6753 g_debug := g_debug||' FV_PREPAY_PKG Failed : '||SQLERRM;
6754 return FALSE;
6755
6756 END fv_prepay_pkg;
6757
6758
6759
6760 /* ============================= GLXFAR ================================ */
6761
6762 -- Update affect_funds_flag in gl_bc_packet_arrival
6763 --
6764 -- This is called from glxfrs() and is executed in an autonomous scope
6765 -- so that the calling programs work is not commited.
6766 --
6767
6768 FUNCTION glxfar RETURN BOOLEAN IS
6769 PRAGMA AUTONOMOUS_TRANSACTION;
6770 -- ========================= FND LOG ===========================
6771 l_full_path VARCHAR2(100);
6772 -- ========================= FND LOG ===========================
6773
6774 BEGIN
6775
6776 l_full_path := g_path || 'glxfar';
6777
6778 -- ========================= FND LOG ===========================
6779 psa_utils.debug_other_string(g_state_level,l_full_path, ' GLXFAR -> START ');
6780 -- ========================= FND LOG ===========================
6781
6782 -- Update Affect Funds Flag to 'N' if Mode is Reservation and Return Code
6783 -- is Failure
6784
6785 if ((g_fcmode <> 'C') and
6786 (g_return_code = 'F')) then
6787 begin
6788
6789 update gl_bc_packet_arrival_order ao
6790 set ao.affect_funds_flag = 'N'
6791 where ao.packet_id = g_packet_id;
6792
6793 -- ========================= FND LOG ===========================
6794 psa_utils.debug_other_string(g_state_level,l_full_path,
6795 ' update gl_bc_packet_arrival_order -> ' || SQL%ROWCOUNT);
6796 -- ========================= FND LOG ===========================
6797
6798 -- Commit so that a later rollback does not reset this flag
6799 commit;
6800
6801 -- ========================= FND LOG ===========================
6802 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN - TRUE');
6803 -- ========================= FND LOG ===========================
6804 RETURN (TRUE);
6805
6806 end;
6807 end if;
6808
6809 commit;
6810 -- ========================= FND LOG ===========================
6811 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN - TRUE');
6812 -- ========================= FND LOG ===========================
6813 RETURN (TRUE);
6814
6815 EXCEPTION
6816
6817 WHEN OTHERS THEN
6818
6819 message_token('PROCEDURE', 'Funds Checker : glxfar');
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||' GLXFAR Failed : '||SQLERRM;
6829 -- bug 3471744
6830 rollback;
6831 return (FALSE);
6832
6833 END;
6834
6835 /* =============================== GLXCON ================================ */
6836
6837 FUNCTION glxcon RETURN BOOLEAN IS
6838 others EXCEPTION;
6839 -- ========================= FND LOG ===========================
6840 l_full_path VARCHAR2(100);
6841 -- ========================= FND LOG ===========================
6842
6843 BEGIN
6844
6845 l_full_path := g_path || 'glxcon.';
6846
6847 -- ========================= FND LOG ===========================
6848 psa_utils.debug_other_string(g_state_level,l_full_path, ' GLXCON -> START ');
6849 psa_utils.debug_other_string(g_state_level,l_full_path, ' Calling glxfrs .. ');
6850 -- ========================= FND LOG ===========================
6851
6852 -- Get Return Status
6853 if not glxfrs then
6854 -- ========================= FND LOG ===========================
6855 psa_utils.debug_other_string(g_state_level,l_full_path, ' GLXFRS - RETURN FALSE ');
6856 psa_utils.debug_other_string(g_state_level,l_full_path, ' goto fatal_error label ');
6857 -- ========================= FND LOG ===========================
6858 goto fatal_error;
6859 end if;
6860
6861 -- ========================= FND LOG ===========================
6862 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_fcmode -> ' || g_fcmode);
6863 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_return_code -> '|| g_return_code);
6864 -- ========================= FND LOG ===========================
6865
6866 -- Process Journal Entries Module if all transactions pass Funds
6867 -- (Un)Reservation and Append JE Flag is set
6868
6869 if ((g_fcmode in ('R', 'U', 'A', 'F')) and
6870 (g_return_code in ('S', 'A'))) then
6871
6872 if g_append_je_flag then
6873 -- ========================= FND LOG ===========================
6874 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_append_je_flag -> TRUE');
6875 psa_utils.debug_other_string(g_state_level,l_full_path, ' Calling glxfje ..');
6876 -- ========================= FND LOG ===========================
6877
6878 if not glxfje then
6879 -- ========================= FND LOG ===========================
6880 psa_utils.debug_other_string(g_state_level,l_full_path, ' GLXFJE RETURN FALSE ');
6881 psa_utils.debug_other_string(g_state_level,l_full_path, ' goto fatal_error label ');
6882 -- ========================= FND LOG ===========================
6883 goto fatal_error;
6884 end if;
6885
6886 end if;
6887
6888 -- Delete the Packet being Unreserved and the generated Unreserved
6889 -- Packet if it passes Funds Unreservation
6890
6891 if g_fcmode = 'U' then
6892
6893 -- ========================= FND LOG ===========================
6894 psa_utils.debug_other_string(g_state_level,l_full_path, ' Calling glxfpp .. ');
6895 -- ========================= FND LOG ===========================
6896 glxfpp(g_packet_id, g_packet_id_ursvd);
6897
6898 -- If Journal Entries were deleted then Commit
6899 if g_append_je_flag then
6900 -- ========================= FND LOG ===========================
6901 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_append_je_flag -> TRUE ');
6902 psa_utils.debug_other_string(g_state_level,l_full_path, ' COMMIT ');
6903 -- ========================= FND LOG ===========================
6904 commit;
6905 end if;
6906
6907 end if;
6908 end if;
6909
6910 -- ========================= FND LOG ===========================
6911 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN -> TRUE ');
6912 -- ========================= FND LOG ===========================
6913 return(TRUE);
6914
6915 <<fatal_error>>
6916 -- ========================= FND LOG ===========================
6917 psa_utils.debug_other_string(g_state_level,l_full_path, ' Reached fatal_error label ');
6918 psa_utils.debug_other_string(g_state_level,l_full_path, ' Calling glxfuf .. ');
6919 -- ========================= FND LOG ===========================
6920
6921 if not glxfuf then
6922 -- ========================= FND LOG ===========================
6923 psa_utils.debug_other_string(g_state_level,l_full_path, ' GLXFUF - RETURN FALSE ');
6924 psa_utils.debug_other_string(g_state_level,l_full_path, ' RASIE OTHERS ');
6925 -- ========================= FND LOG ===========================
6926 raise others;
6927 end if;
6928
6929 -- ========================= FND LOG ===========================
6930 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN -> FALSE ');
6931 -- ========================= FND LOG ===========================
6932 g_debug := g_debug||' GLXCON Failed';
6933 return(FALSE);
6934
6935 EXCEPTION
6936
6937 WHEN OTHERS THEN
6938
6939 message_token('PROCEDURE', 'Funds Checker');
6940 message_token('EVENT', SQLERRM);
6941 add_message('SQLGL', 'GL_UNHANDLED_EXCEPTION');
6942
6943 -- ========================= FND LOG ===========================
6944 psa_utils.debug_other_string(g_excep_level,l_full_path, ' EXCEPTION WHEN OTHERS ' || SQLERRM);
6945 psa_utils.debug_other_string(g_excep_level,l_full_path, ' RETURN -> FALSE ');
6946 -- ========================= FND LOG ===========================
6947 g_debug := g_debug||' GLXCON Failed : '||SQLERRM;
6948 return(FALSE);
6949
6950 END glxcon;
6951
6952 /*=======================================================================+
6953 | Function : GLUREVD |
6954 | Description : This is a replica of function glurevd_default_reversal |
6955 | in file $GL_TOP/src/utils/glurevd.lpc |
6956 +=======================================================================*/
6957
6958 FUNCTION glurevd ( p_ledger_id NUMBER,
6959 p_je_category VARCHAR2,
6960 p_je_source VARCHAR2,
6961 p_je_period VARCHAR2,
6962 p_je_date DATE,
6963 x_reversal_method OUT NOCOPY VARCHAR2,
6964 p_balance_type VARCHAR2) RETURN BOOLEAN IS
6965
6966 l_je_reversal_date DATE;
6967 l_reversal_method VARCHAR2(1);
6968 l_reversal_period VARCHAR2(15);
6969 l_reversal_date DATE;
6970 -- ========================= FND LOG ===========================
6971 l_full_path VARCHAR2(100);
6972 -- ========================= FND LOG ===========================
6973 BEGIN
6974
6975 l_full_path := g_path || 'glurevd';
6976
6977 -- ========================= FND LOG ===========================
6978 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_ledger_id -> ' || p_ledger_id);
6979 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_je_category -> ' || p_je_category);
6980 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_je_source -> ' || p_je_source);
6981 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_je_period -> ' || p_je_period);
6982 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_je_date -> '
6983 || to_char(p_je_date, 'DD-MON-YYYY'));
6984 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_balance_type -> ' || p_balance_type);
6985 -- ========================= FND LOG ===========================
6986
6987 IF (p_balance_type = 'A') THEN
6988 BEGIN
6989 GL_AUTOREVERSE_DATE_PKG.GET_REVERSAL_PERIOD_DATE(
6990 x_ledger_id => p_ledger_id,
6991 x_je_category => p_je_category,
6992 x_je_source => p_je_source,
6993 x_je_period_name => p_je_period,
6994 x_je_date => p_je_date,
6995 x_reversal_method => l_reversal_method,
6996 x_reversal_period => l_reversal_period,
6997 x_reversal_date => l_reversal_date);
6998 EXCEPTION
6999 WHEN OTHERS THEN
7000 -- ========================= FND LOG ===========================
7001 psa_utils.debug_other_string(g_excep_level,l_full_path,
7002 'Call to GL_AUTOREVERSE_DATE_PKG raised unhandled exception - '
7003 ||sqlcode||' - '||sqlerrm);
7004 psa_utils.debug_unexpected_msg(l_full_path);
7005 -- ========================= FND LOG ===========================
7006
7007 GL_AUTOREVERSE_DATE_PKG.get_default_reversal_method(
7008 g_ledger_id, p_je_category, l_reversal_method);
7009
7010 -- ========================= FND LOG ===========================
7011 psa_utils.debug_other_string(g_excep_level,l_full_path,
7012 'l_reversal_method value returned by get_default_reversal_method : '||l_reversal_method);
7013 -- ========================= FND LOG ===========================
7014
7015 END;
7016
7017 ELSE
7018
7019 GL_AUTOREVERSE_DATE_PKG.get_default_reversal_method(
7020 g_ledger_id, p_je_category, l_reversal_method);
7021
7022 -- ========================= FND LOG ===========================
7023 psa_utils.debug_other_string(g_excep_level,l_full_path,
7024 'l_reversal_method value returned by get_default_reversal_method : '||l_reversal_method);
7025 -- ========================= FND LOG ===========================
7026
7027 END IF;
7028
7029 IF (l_reversal_method IS NOT NULL) THEN
7030
7031 -- ========================= FND LOG ===========================
7032 psa_utils.debug_other_string(g_excep_level,l_full_path,'x_reversal_method -> l_reversal_method');
7033 psa_utils.debug_other_string(g_excep_level,l_full_path,'Return -> True');
7034 -- ========================= FND LOG ===========================
7035
7036 x_reversal_method := l_reversal_method;
7037 return TRUE;
7038 ELSE
7039 -- ========================= FND LOG ===========================
7040 psa_utils.debug_other_string(g_excep_level,l_full_path,'Return -> False');
7041 -- ========================= FND LOG ===========================
7042
7043 return FALSE;
7044 END IF;
7045
7046 EXCEPTION
7047 WHEN OTHERS THEN
7048 -- ========================= FND LOG ===========================
7049 psa_utils.debug_other_string(g_excep_level,l_full_path,
7050 'Exception raised in main body execution - '||sqlcode||' - '||sqlerrm);
7051 psa_utils.debug_unexpected_msg(l_full_path);
7052 -- ========================= FND LOG ===========================
7053 g_debug := g_debug||' GLUREVD Failed : '||SQLERRM;
7054 x_reversal_method := NULL;
7055 return FALSE;
7056
7057 END glurevd;
7058
7059 /*=======================================================================+
7060 | Function : GL_CONFIRM_OVERRIDE |
7061 | Description : Applicable on for GL. This function is added so that GL |
7062 | can pop up a window for confirming override of the trx |
7063 | and once the user decides, GL invokes this function |
7064 | so that funds check can proceed accordingly. |
7065 +=======================================================================*/
7066
7067 FUNCTION gl_confirm_override(p_ledgerid IN NUMBER,
7068 p_packetid IN NUMBER,
7069 p_mode IN VARCHAR2 DEFAULT 'C',
7070 p_override IN VARCHAR2 DEFAULT 'N',
7071 p_conc_flag IN VARCHAR2 DEFAULT 'N',
7072 p_user_id IN NUMBER DEFAULT NULL,
7073 p_user_resp_id IN NUMBER DEFAULT NULL,
7074 p_calling_prog_flag IN VARCHAR2 DEFAULT 'G',
7075 p_confirm_override IN VARCHAR2 DEFAULT 'Y',
7076 p_return_code OUT NOCOPY VARCHAR2,
7077 p_unrsv_packet_id OUT NOCOPY NUMBER) RETURN BOOLEAN IS
7078
7079
7080 cursor append_je is
7081 select 'Associated Generated JEs to be appended or inserted'
7082 from dual
7083 where exists
7084 (
7085 select 'Associated Generated Row from existing GL Batch'
7086 from gl_bc_packets bp
7087 where bp.packet_id = g_packet_id
7088 and bp.je_batch_id is not null
7089 and bp.je_batch_id >= 0
7090 and bp.ussgl_transaction_code is not null
7091 );
7092
7093 OTHERS EXCEPTION;
7094 l_dummy VARCHAR2(100);
7095 -- ========================= FND LOG ===========================
7096 l_full_path VARCHAR2(100);
7097 -- ========================= FND LOG ===========================
7098 BEGIN
7099 l_full_path := g_path || 'gl_confirm_override';
7100
7101 -- ========================= FND LOG ===========================
7102 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_ledgerid -> ' || p_ledgerid);
7103 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_packetid -> ' || p_packetid);
7104 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_mode -> ' || p_mode);
7105 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_override -> ' || p_override);
7106 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_conc_flag -> ' || p_conc_flag);
7107 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_user_id -> ' || p_user_id);
7108 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_calling_prog_flag -> ' || p_calling_prog_flag);
7109 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_confirm_override -> ' || p_confirm_override);
7110 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_user_resp_id -> ' || p_user_resp_id);
7111 -- ========================= FND LOG ===========================
7112
7113 if p_calling_prog_flag <> 'G' then
7114
7115 -- =========================== FND LOG ===========================
7116 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_calling_prog_flag <> G -> raise others');
7117 -- ========================= FND LOG =============================
7118
7119 raise others;
7120 end if;
7121
7122 -- Initialize Global Variables
7123 if not glxfin(p_ledgerid => p_ledgerid,
7124 p_packetid => p_packetid,
7125 p_mode => p_mode,
7126 p_override => p_override,
7127 p_conc_flag => p_conc_flag,
7128 p_user_id => p_user_id,
7129 p_user_resp_id => p_user_resp_id,
7130 p_calling_prog_flag => p_calling_prog_flag) then
7131
7132 -- =========================== FND LOG ===========================
7133 psa_utils.debug_other_string(g_state_level,l_full_path, ' glxfin --> RETURN FALSE -> goto fatal_error');
7134 -- ========================= FND LOG =============================
7135
7136 goto fatal_error;
7137 end if;
7138
7139 -- Override Transactions
7140 if (g_override_flag) and (p_confirm_override = 'Y') then
7141 -- =========================== FND LOG ===========================
7142 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_override_flag --> TRUE ');
7143 -- ========================= FND LOG =============================
7144
7145 if not glxfor then
7146 -- =========================== FND LOG ===========================
7147 psa_utils.debug_other_string(g_state_level,l_full_path, ' glxfor --> RETURN FALSE -> goto fatal_error');
7148 -- ========================= FND LOG =============================
7149 goto fatal_error;
7150 end if;
7151
7152 else
7153 -- =========================== FND LOG ===========================
7154 psa_utils.debug_other_string(g_state_level,l_full_path, ' g_override_flag --> FALSE ');
7155 -- ========================= FND LOG =============================
7156 end if;
7157
7158 -- =========================== FND LOG ===========================
7159 psa_utils.debug_other_string(g_state_level,l_full_path, ' Calling glxcon ');
7160 -- ========================= FND LOG =============================
7161
7162 open append_je;
7163 fetch append_je into l_dummy;
7164 if (append_je%found) then
7165 g_append_je_flag := true;
7166 else
7167 g_append_je_flag := false;
7168 end if;
7169 close append_je;
7170
7171 -- Set Result Codes, Return Code, Append Journal Logic
7172 if not glxcon then
7173 -- =========================== FND LOG ===========================
7174 psa_utils.debug_other_string(g_state_level,l_full_path, ' glxcon --> RETURN FALSE -> goto fatal_error');
7175 -- ========================= FND LOG =============================
7176 goto fatal_error;
7177 end if;
7178
7179 -- =========================== FND LOG ===========================
7180 psa_utils.debug_other_string(g_state_level,l_full_path, ' Calling glrchk ');
7181 -- ========================= FND LOG =============================
7182
7183 if not glrchk('X') then
7184 -- =========================== FND LOG ===========================
7185 psa_utils.debug_other_string(g_state_level,l_full_path, ' glrchk(X) --> RETURN FALSE -> goto fatal_error');
7186 -- ========================= FND LOG =============================
7187 goto fatal_error;
7188 end if;
7189
7190 -- =========================== FND LOG ===========================
7191 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_return_code = g_return_code --> ' || g_return_code);
7192 -- ========================= FND LOG =============================
7193
7194 p_return_code := g_return_code;
7195
7196 -- =========================== FND LOG ===========================
7197 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN --> TRUE ');
7198 -- ========================= FND LOG =============================
7199
7200 IF (p_mode = 'U' AND NOT g_requery_flag) THEN
7201 p_unrsv_packet_id := p_packetid;
7202 -- ========================= FND LOG ===========================
7203 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_unrsv_packet_id --> ' || p_unrsv_packet_id );
7204 -- ========================= FND LOG ===========================
7205 END IF;
7206
7207 -- If g_requery_flag is TRUE set p_return_code = "Q"
7208 -- for calling form (MJE) to requery instead of the
7209 -- regular commit. [p_return code "Q" => Success/Advisory]
7210
7211 IF g_requery_flag THEN
7212 p_return_code := 'Q';
7213 -- ========================= FND LOG ===========================
7214 psa_utils.debug_other_string(g_state_level,l_full_path, ' p_return_code --> Q => Success/Advisory ');
7215 -- ========================= FND LOG ===========================
7216 END IF;
7217
7218 -- ========================= FND LOG ===========================
7219 psa_utils.debug_other_string(g_state_level,l_full_path, ' Return -> True');
7220 -- ========================= FND LOG ===========================
7221
7222 return(TRUE);
7223
7224 <<fatal_error>>
7225
7226 -- =========================== FND LOG ===========================
7227 psa_utils.debug_other_string(g_state_level,l_full_path, ' Reached FATAL ERROR LABEL ');
7228 -- ========================= FND LOG =============================
7229
7230 if not glxfuf then
7231 -- =========================== FND LOG ===========================
7232 psa_utils.debug_other_string(g_state_level,l_full_path, ' glxfuf --> RETURN FALSE -> RAISE OTHERS');
7233 -- ========================= FND LOG =============================
7234 raise others;
7235 end if;
7236
7237 -- =========================== FND LOG ===========================
7238 psa_utils.debug_other_string(g_state_level,l_full_path, ' RETURN -> FALSE ');
7239 -- ========================= FND LOG =============================
7240
7241 g_debug := g_debug||' GL_CONFIRM_OVERRIDE Failed';
7242 return(FALSE);
7243
7244 EXCEPTION
7245
7246 WHEN OTHERS THEN
7247 -- =========================== FND LOG ===========================
7248 psa_utils.debug_other_string(g_excep_level,l_full_path, ' EXCEPTION WHEN OTHERS ' || SQLERRM);
7249 psa_utils.debug_other_string(g_excep_level,l_full_path, ' RETURN -> FALSE ');
7250 -- ========================= FND LOG =============================
7251
7252 message_token('PROCEDURE', 'Funds Checker');
7253 message_token('EVENT', SQLERRM);
7254 add_message('SQLGL', 'GL_UNHANDLED_EXCEPTION');
7255 g_debug := g_debug||' GL_CONFIRM_OVERRIDE Failed : '||SQLERRM;
7256 return(FALSE);
7257
7258 END gl_confirm_override;
7259
7260
7261 /*=======================================================================+
7262 | Function : OPTIMIZE_PACKETS |
7263 | Description : Invoked by bc_optimizer rountine. This acts as a pvt |
7264 | function. Function deletes rows from gl_bc_packets and |
7265 | inserts them in gl_bc_packets_hists. Only rows with |
7266 | status_code R, S, F, T, P, C are deleted. |
7267 +=======================================================================*/
7268
7269 PROCEDURE optimize_packets (p_ledger_id IN NUMBER, p_purge_days IN NUMBER) IS
7270 l_full_path VARCHAR2(100);
7271 BEGIN
7272 l_full_path := g_path||'Optimize_Packets';
7273
7274 /*-----------------------------------------------------------------------+
7275 | New criteria for deleting rows from gl_bc_packets is as below: |
7276 | |
7277 | Status_Code: |
7278 | =========== |
7279 | R, S, F, T - All rows for the p_ledger_id |
7280 | - These rows should get inserted in gl_bc_packets_hists |
7281 | |
7282 | P, C - All rows for the p_ledger_id for which session has |
7283 | expired or which are older than 5 days (120 hours) |
7284 | - These rows should not be stored in gl_bc_packets_hists |
7285 | |
7286 +----------------------------------------------------------------------*/
7287
7288
7289 DELETE from gl_bc_packets Q
7290 where
7291 Q.status_code IN ('P', 'C')
7292 and ((((sysdate - Q.last_update_date)*24) > 48) OR
7293 (NOT EXISTS (SELECT 'x'
7294 FROM v$session
7295 WHERE audsid = Q.session_id
7296 and Serial# = Q.serial_id)));
7297
7298 -- =========================== FND LOG ===========================
7299 psa_utils.debug_other_string(g_state_level,l_full_path, ' Delete gl_bc_packets 1 deleted ' || SQL%ROWCOUNT || ' rows');
7300 -- ========================= FND LOG =============================
7301
7302
7303 DELETE from gl_bc_packets Q
7304 where
7305 Q.ledger_id = p_ledger_id
7306 and Q.status_code in ('R','S','F', 'T') returning
7307 PACKET_ID,
7308 LEDGER_ID,
7309 JE_SOURCE_NAME,
7310 JE_CATEGORY_NAME,
7311 CODE_COMBINATION_ID,
7312 ACTUAL_FLAG,
7313 PERIOD_NAME,
7314 PERIOD_YEAR,
7315 PERIOD_NUM,
7316 QUARTER_NUM,
7317 CURRENCY_CODE,
7318 STATUS_CODE,
7319 LAST_UPDATE_DATE,
7320 LAST_UPDATED_BY,
7321 BUDGET_VERSION_ID,
7322 ENCUMBRANCE_TYPE_ID,
7323 TEMPLATE_ID,
7324 ENTERED_DR,
7325 ENTERED_CR,
7326 ACCOUNTED_DR,
7327 ACCOUNTED_CR,
7328 USSGL_TRANSACTION_CODE,
7329 ORIGINATING_ROWID,
7330 ACCOUNT_SEGMENT_VALUE,
7331 AUTOMATIC_ENCUMBRANCE_FLAG,
7332 FUNDING_BUDGET_VERSION_ID,
7333 FUNDS_CHECK_LEVEL_CODE,
7334 AMOUNT_TYPE,
7335 BOUNDARY_CODE,
7336 TOLERANCE_PERCENTAGE,
7337 TOLERANCE_AMOUNT,
7338 OVERRIDE_AMOUNT,
7339 DR_CR_CODE,
7340 ACCOUNT_TYPE,
7341 ACCOUNT_CATEGORY_CODE,
7342 EFFECT_ON_FUNDS_CODE,
7343 RESULT_CODE,
7344 BUDGET_POSTED_BALANCE,
7345 ACTUAL_POSTED_BALANCE,
7346 ENCUMBRANCE_POSTED_BALANCE,
7347 BUDGET_APPROVED_BALANCE,
7348 ACTUAL_APPROVED_BALANCE,
7349 ENCUMBRANCE_APPROVED_BALANCE,
7350 BUDGET_PENDING_BALANCE,
7351 ACTUAL_PENDING_BALANCE,
7352 ENCUMBRANCE_PENDING_BALANCE,
7353 REFERENCE1,
7354 REFERENCE2,
7355 REFERENCE3,
7356 REFERENCE4,
7357 REFERENCE5,
7358 JE_BATCH_NAME,
7359 JE_BATCH_ID,
7360 JE_HEADER_ID,
7361 JE_LINE_NUM,
7362 JE_LINE_DESCRIPTION,
7363 REFERENCE6,
7364 REFERENCE7,
7365 REFERENCE8,
7366 REFERENCE9,
7367 REFERENCE10,
7368 REFERENCE11,
7369 REFERENCE12,
7370 REFERENCE13,
7371 REFERENCE14,
7372 REFERENCE15,
7373 REQUEST_ID,
7374 USSGL_PARENT_ID,
7375 USSGL_LINK_TO_PARENT_ID,
7376 EVENT_ID,
7377 AE_HEADER_ID,
7378 AE_LINE_NUM,
7379 BC_DATE,
7380 SOURCE_DISTRIBUTION_TYPE,
7381 SOURCE_DISTRIBUTION_ID_CHAR_1,
7382 SOURCE_DISTRIBUTION_ID_CHAR_2,
7383 SOURCE_DISTRIBUTION_ID_CHAR_3,
7384 SOURCE_DISTRIBUTION_ID_CHAR_4,
7385 SOURCE_DISTRIBUTION_ID_CHAR_5,
7386 SOURCE_DISTRIBUTION_ID_NUM_1,
7387 SOURCE_DISTRIBUTION_ID_NUM_2,
7388 SOURCE_DISTRIBUTION_ID_NUM_3,
7389 SOURCE_DISTRIBUTION_ID_NUM_4,
7390 SOURCE_DISTRIBUTION_ID_NUM_5,
7391 SESSION_ID,
7392 SERIAL_ID,
7393 APPLICATION_ID,
7394 ENTITY_ID,
7395 GROUP_ID
7396 bulk collect into g_bc_pkts_hist;
7397
7398 -- =========================== FND LOG ===========================
7399 psa_utils.debug_other_string(g_state_level,l_full_path, ' Delete gl_bc_packets 2 deleted ' || SQL%ROWCOUNT || ' rows');
7400 -- ========================= FND LOG =============================
7401
7402
7403 FORALL i IN 1..g_bc_pkts_hist.count
7404 insert into gl_bc_packets_hists
7405 values g_bc_pkts_hist(i);
7406
7407 if p_purge_days > 0 then
7408
7409 DELETE from psa_bc_accounting_errors
7410 where (sysdate - creation_date) >= p_purge_days;
7411
7412 -- =========================== FND LOG ===========================
7413 psa_utils.debug_other_string(g_state_level,l_full_path, ' Delete psa_bc_accounting_errors deleted ' || SQL%ROWCOUNT || ' rows');
7414 -- ========================= FND LOG =============================
7415
7416 DELETE from psa_xla_validation_lines_logs
7417 where (sysdate - creation_date) >= p_purge_days;
7418
7419 -- =========================== FND LOG ===========================
7420 psa_utils.debug_other_string(g_state_level,l_full_path, ' Delete psa_xla_validation_lines_logs deleted ' || SQL%ROWCOUNT || ' rows');
7421 -- ========================= FND LOG =============================
7422
7423 DELETE from psa_xla_events_logs
7424 where (sysdate - creation_date) >= p_purge_days;
7425
7426 -- =========================== FND LOG ===========================
7427 psa_utils.debug_other_string(g_state_level,l_full_path, ' Delete psa_xla_events_logs deleted ' || SQL%ROWCOUNT || ' rows');
7428 -- ========================= FND LOG =============================
7429
7430 DELETE from psa_xla_ae_lines_logs
7431 where (sysdate - creation_date) >= p_purge_days;
7432
7433 -- =========================== FND LOG ===========================
7434 psa_utils.debug_other_string(g_state_level,l_full_path, ' Delete psa_xla_ae_lines_logs deleted ' || SQL%ROWCOUNT || ' rows');
7435 -- ========================= FND LOG =============================
7436
7437 DELETE from psa_xla_ae_headers_logs
7438 where (sysdate - creation_date) >= p_purge_days;
7439
7440 -- =========================== FND LOG ===========================
7441 psa_utils.debug_other_string(g_state_level,l_full_path, ' Delete psa_xla_ae_header_logs deleted ' || SQL%ROWCOUNT || ' rows');
7442 -- ========================= FND LOG =============================
7443
7444 -- ========================= FND LOG =============================
7445
7446 DELETE from psa_xla_dist_links_logs
7447 where (sysdate - creation_date) >= p_purge_days;
7448
7449 -- =========================== FND LOG ===========================
7450 psa_utils.debug_other_string(g_state_level,l_full_path, ' Delete psa_xla_dist_links_logs deleted ' || SQL%ROWCOUNT || ' rows');
7451 -- ========================= FND LOG =============================
7452
7453 end if;
7454
7455 END optimize_packets;
7456
7457
7458 /*=======================================================================+
7459 | Function : BC_OPTIMIZER |
7460 | Description : Invoked by SRS "Budgetary Control Optimizer" |
7461 +=======================================================================*/
7462
7463 PROCEDURE bc_optimizer (err_buf OUT NOCOPY VARCHAR2,
7464 ret_code OUT NOCOPY VARCHAR2,
7465 p_ledger_id IN NUMBER,
7466 p_purge_days IN NUMBER) IS
7467 BEGIN
7468
7469 optimize_packets(p_ledger_id, p_purge_days);
7470
7471 commit;
7472
7473 END bc_optimizer;
7474
7475 /*=======================================================================+
7476 | Function : BC_PURGE_HIST |
7477 | Description : Invoked by SRS "Budgetary Control History Purge" |
7478 | Deletes rows from gl_bc_packets_hists depending upon |
7479 | the criteria selected by user while running SRS |
7480 +=======================================================================*/
7481
7482 PROCEDURE bc_purge_hist (err_buf OUT NOCOPY VARCHAR2,
7483 ret_code OUT NOCOPY VARCHAR2,
7484 p_ledger_id IN NUMBER,
7485 p_purge_mode IN VARCHAR2,
7486 p_purge_statuses IN VARCHAR2,
7487 p_purge_date IN VARCHAR2) IS
7488
7489 l_stmt VARCHAR2(5000);
7490 l_status_code VARCHAR2(50);
7491 l_purge_date DATE;
7492 l_full_path VARCHAR2(100);
7493 BEGIN
7494 l_full_path := g_path||'Bc_Purge_Hist';
7495
7496 optimize_packets(p_ledger_id, 0);
7497
7498 l_purge_date := TO_DATE(p_purge_date, 'YYYY/MM/DD HH24:MI:SS');
7499
7500 -- =========================== FND LOG ===========================
7501 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'));
7502 -- ========================= FND LOG =============================
7503
7504
7505 l_stmt := 'delete from gl_bc_packets_hists '||
7506 'where (last_update_date < :purge_date) '||
7507 ' and ledger_id = :p_ledger_id ';
7508
7509 l_status_code := CASE p_purge_mode||p_purge_statuses
7510 WHEN 'CP' THEN '''S'''
7511 WHEN 'CF' THEN '''F'''
7512 WHEN 'CE' THEN '''T'''
7513 WHEN 'CA' THEN '''S'', ''F'', ''T'''
7514 WHEN 'RP' THEN '''A'''
7515 WHEN 'RF' THEN '''R'''
7516 WHEN 'RE' THEN '''T'''
7517 WHEN 'RA' THEN '''A'', ''R'', ''T'''
7518 WHEN 'AP' THEN '''S'', ''A'''
7519 WHEN 'AF' THEN '''F'', ''R'''
7520 WHEN 'AE' THEN '''T'''
7521 WHEN 'AA' THEN '''S'', ''F'', ''A'', ''R'', ''T'''
7522 END;
7523
7524 l_stmt := l_stmt ||'and status_code IN ('||l_status_code||')';
7525
7526 -- =========================== FND LOG ===========================
7527 psa_utils.debug_other_string(g_state_level,l_full_path, ' l_stmt -> ' || l_stmt);
7528 -- ========================= FND LOG =============================
7529
7530
7531 execute immediate l_stmt using l_purge_date, p_ledger_id;
7532
7533 commit;
7534
7535 END bc_purge_hist;
7536
7537 /*=======================================================================+
7538 | Function : GET_PACKET_ID |
7539 | Description : Returns the next packet_id using gl_bc_packets_s seq |
7540 +=======================================================================*/
7541
7542 FUNCTION get_packet_id RETURN NUMBER IS
7543 l_pkt_id gl_bc_packets.packet_id%type;
7544 l_full_path VARCHAR2(100);
7545 BEGIN
7546
7547 l_full_path := g_path||'Get_Packet_Id';
7548
7549 select gl_bc_packets_s.nextval into l_pkt_id
7550 from dual;
7551
7552 -- =========================== FND LOG ===========================
7553 psa_utils.debug_other_string(g_state_level,l_full_path, ' l_pkt_id -> ' || l_pkt_id);
7554 -- ========================= FND LOG =============================
7555
7556 return l_pkt_id;
7557 END get_packet_id;
7558
7559 /*=======================================================================+
7560 | Function : POPULATE_BC_PKTS |
7561 | Description : Inserts data in gl_bc_packets using the plsql table |
7562 | passed as parameter. Commits in autonomous mode. |
7563 +=======================================================================*/
7564
7565 FUNCTION populate_bc_pkts (p_bc_pkts IN BC_PKTS_REC) RETURN BOOLEAN IS
7566
7567 -- ========================= FND LOG ===========================
7568 l_full_path VARCHAR2(100);
7569 -- ========================= FND LOG ===========================
7570 pragma autonomous_transaction;
7571
7572 BEGIN
7573
7574 l_full_path := g_path||'Populate_Bc_pkts';
7575
7576 -- Now that plsql table is populated, insert data in gl_bc_packets.
7577
7578 FORALL i IN 1..p_bc_pkts.count
7579 INSERT INTO gl_bc_packets
7580 VALUES p_bc_pkts(i);
7581
7582 commit;
7583
7584 RETURN TRUE;
7585
7586 EXCEPTION
7587 WHEN OTHERS THEN
7588 psa_utils.debug_other_string(g_excep_level,l_full_path, ' BCTRL -> '||sqlerrm);
7589 rollback;
7590 RETURN FALSE;
7591
7592 END populate_bc_pkts;
7593
7594
7595 /*=======================================================================+
7596 | Procedure : GLXFMA |
7597 | Description : Invoked by Concurrent Program for Mass Funds Check, |
7598 | Reserve etc. Upgraded from 11i. |
7599 +=======================================================================*/
7600 PROCEDURE glxfma ( err_buf OUT NOCOPY VARCHAR2,
7601 ret_code OUT NOCOPY VARCHAR2,
7602 p_ledger_id IN NUMBER,
7603 p_check_flag IN VARCHAR2,
7604 p_autopost_set_id IN NUMBER) IS
7605 CURSOR sel1 is
7606
7607 SELECT
7608 B.actual_flag,
7609 H.je_source,
7610 B.default_period_name,
7611 B.je_batch_id,
7612 substrb(B.name,1,88)
7613 FROM
7614 gl_je_headers H,
7615 gl_je_batches B,
7616 gl_automatic_posting_options O,
7617 gl_automatic_posting_sets S
7618 WHERE
7619 S.autopost_set_id = p_autopost_set_id
7620 AND S.autopost_set_id = O.autopost_set_id
7621 AND o.ledger_id = H.ledger_id
7622 AND B.actual_flag = decode(O.actual_flag,
7623 'L', B.actual_flag,
7624 O.actual_flag)
7625 AND B.default_period_name = decode(O.period_name,
7626 'ALL', B.default_period_name,
7627 O.period_name)
7628 AND B.je_batch_id = H.je_batch_id
7629 AND H.je_source = decode(O.je_source_name,
7630 'ALL', H.je_source,
7631 O.je_source_name)
7632 AND B.status = 'U'
7633 AND B.budgetary_control_status in ('R', 'F')
7634 AND NOT EXISTS
7635 ( SELECT 'Not all category match'
7636 FROM GL_JE_HEADERS H2
7637 WHERE
7638 H2.je_batch_id = B.je_batch_id
7639 AND H2.je_category <> decode(O.je_category_name,
7640 'ALL', H2.je_category,
7641 O.je_category_name) )
7642 AND NOT EXISTS
7643 ( SELECT 'Untaxed Journals'
7644 FROM GL_JE_HEADERS GLH
7645 WHERE GLH.tax_status_code = 'R'
7646 AND GLH.je_batch_id = B.je_batch_id
7647 AND B.actual_flag = 'A'
7648 AND GLH.currency_code <> 'STAT'
7649 AND GLH.je_source = 'Manual' )
7650 GROUP BY B.je_batch_id, B.actual_flag,
7651 B.default_period_name,B.name,H.je_source
7652 ORDER BY B.default_period_name,B.actual_flag;
7653
7654 CURSOR sel2 is
7655
7656 SELECT
7657 b.actual_flag,
7658 h.je_source,
7659 b.default_period_name,
7660 b.je_batch_id,
7661 substrb(b.name,1,88)
7662 FROM
7663 gl_je_headers h,
7664 gl_je_batches b,
7665 gl_automatic_posting_options o,
7666 gl_automatic_posting_sets s
7667 WHERE
7668 s.autopost_set_id = p_autopost_set_id
7669 AND s.autopost_set_id = o.autopost_set_id
7670 AND o.ledger_id = H.ledger_id
7671 AND b.actual_flag = decode(o.actual_flag,
7672 'L', b.actual_flag,
7673 o.actual_flag)
7674 AND b.default_period_name = decode(o.period_name,
7675 'ALL', b.default_period_name,
7676 o.period_name)
7677 AND b.je_batch_id = h.je_batch_id
7678 AND h.je_source = decode(o.je_source_name,
7679 'ALL', h.je_source,
7680 o.je_source_name)
7681 AND b.status = 'U'
7682 AND b.budgetary_control_status in ('R', 'F')
7683 AND NOT EXISTS
7684 ( SELECT 'Not all category match'
7685 FROM gl_je_headers h2
7686 WHERE
7687 h2.je_batch_id = b.je_batch_id
7688 AND h2.je_category <> decode(o.je_category_name,
7689 'ALL', h2.je_category,
7690 o.je_category_name) )
7691 GROUP BY b.je_batch_id, b.actual_flag,
7692 b.default_period_name,b.name,h.je_source
7693 ORDER BY b.default_period_name,b.actual_flag;
7694
7695 CURSOR c_seg_info (p_ledger_id NUMBER) IS
7696
7697 SELECT
7698 application_column_name
7699 FROM
7700 fnd_id_flex_segments
7701 WHERE
7702 id_flex_num = (SELECT
7703 chart_of_accounts_id
7704 FROM gl_ledgers
7705 WHERE ledger_id = p_ledger_id)
7706 AND id_flex_code = 'GL#'
7707 AND application_id = 101
7708 AND enabled_flag = 'Y';
7709
7710 TYPE je_ref_cursor IS REF CURSOR;
7711 l_je_lines je_ref_cursor;
7712 l_je_sum_lines je_ref_cursor;
7713 l_je_bud_lines je_ref_cursor;
7714
7715 l_full_path VARCHAR2(100);
7716 l_bc_pkts bc_pkts_rec;
7717 l_bc_pkts_cnt number;
7718 l_tmp_bc_pkts bc_pkts_rec;
7719 l_failed_bc_pkts bc_pkts_rec;
7720 l_failed_bc_pkts_cnt number;
7721 l_sob_name gl_sets_of_books.name%TYPE;
7722 l_budgetary_control_flag gl_sets_of_books.enable_budgetary_control_flag%TYPE;
7723 l_automatic_tax_flag gl_sets_of_books.enable_automatic_tax_flag%TYPE;
7724 l_coa_id gl_sets_of_books.chart_of_accounts_id%TYPE;
7725 l_currency_code gl_sets_of_books.currency_code%TYPE;
7726 l_autopost_set_name gl_automatic_posting_sets.autopost_set_name%TYPE;
7727 l_appl_id fnd_application.application_id%TYPE;
7728 l_resp_id fnd_responsibility.responsibility_id%TYPE;
7729 l_user_id fnd_user.user_id%TYPE;
7730 l_actual_flag gl_je_batches.actual_flag%TYPE;
7731 l_source_name gl_je_headers.je_source%TYPE;
7732 l_period_name gl_je_batches.default_period_name%TYPE;
7733 l_je_batch_id gl_je_batches.je_batch_id%TYPE;
7734 l_batch_name gl_je_batches.name%TYPE;
7735 l_packet_id gl_bc_packets.packet_id%TYPE;
7736 l_main_stmt varchar2(4000);
7737 l_tmp_stmt varchar2(4000);
7738 l_action_stmt varchar2(4000);
7739 l_je_stmt varchar2(4000);
7740 l_bc_not_enabled_msg varchar2(250);
7741 l_msg2 varchar2(250);
7742 l_check_flag varchar2(10);
7743 l_glxfck_return_status boolean;
7744 l_glxfck_return_code varchar2(10);
7745 l_calling_prog_flag varchar2(10);
7746 l_fmeaning varchar2(50);
7747 l_jmeaning varchar2(50);
7748 l_date varchar2(50);
7749 l_header boolean;
7750 l_je_first boolean;
7751 l_ledger_id gl_automatic_posting_options.ledger_id%TYPE;
7752 l_session_id gl_bc_packets.session_id%type;
7753 l_serial_id gl_bc_packets.serial_id%type;
7754 l_seg_ccid varchar2(200);
7755 l_je_header_name gl_je_headers.name%TYPE;
7756 l_je_header_id gl_je_headers.je_header_id%TYPE;
7757 l_je_line_num gl_je_lines.je_line_num%TYPE;
7758 l_entered_dr gl_je_lines.entered_dr%TYPE;
7759 l_entered_cr gl_je_lines.entered_cr%TYPE;
7760 l_line_description gl_lookups.description%TYPE;
7761 l_line_result_code gl_bc_packets.result_code%TYPE;
7762 l_ccid gl_je_lines.code_combination_id%TYPE;
7763 l_rowid varchar2(100);
7764 l_priority gl_lookups.meaning%TYPE;
7765 l_je_seg_stmt varchar2(4000);
7766 l_je_sum_flex varchar2(4000);
7767 l_je_bud_stmt varchar2(4000);
7768 l_je_bud_flex varchar2(4000);
7769 l_je_bud_dr gl_bc_packets.entered_dr%TYPE;
7770 l_je_bud_cr gl_bc_packets.entered_cr%TYPE;
7771 l_je_bud_result_code gl_bc_packets.result_code%TYPE;
7772 l_je_bud_desc gl_lookups.description%TYPE;
7773 l_je_bud_ccid gl_code_combinations.code_combination_id%TYPE;
7774 l_ussgl_parent_id gl_bc_packets.ussgl_parent_id%TYPE;
7775 l_je_bud_seg_stmt varchar2(4000);
7776 l_je_bud_sum_flex varchar2(4000);
7777
7778 -- XML variables
7779 l_xml_b_header boolean;
7780 l_application_name varchar2(300);
7781 l_report_name varchar2(300);
7782 l_funds_action varchar2(300);
7783 l_failure_warning varchar2(500);
7784 l_xml_je_lines_header boolean;
7785 l_xml_f_b_header boolean;
7786 l_xml_f_l_header boolean;
7787 l_xml_f_sum_header boolean;
7788 l_xml_f_bud_header boolean;
7789 l_xml_f_bud_sum_header boolean;
7790
7791 BEGIN
7792
7793 l_full_path := g_path || 'glxfma';
7794 l_check_flag := p_check_flag;
7795 l_ledger_id := p_ledger_id;
7796
7797 --Get the Application Name
7798 FND_MESSAGE.SET_NAME('PSA', 'R_FCMA0031');
7799 l_application_name := FND_MESSAGE.GET();
7800
7801 --Get the Report Name
7802 FND_MESSAGE.SET_NAME('PSA', 'R_FCMA0030');
7803 l_report_name := FND_MESSAGE.GET();
7804
7805 --Get the Funds Action
7806 IF (l_check_flag = 'C' OR l_check_flag = 'M') THEN
7807 FND_MESSAGE.SET_NAME('PSA', 'R_FCMA0032');
7808 ELSIF (l_check_flag = 'R' OR l_check_flag = 'P') THEN
7809 FND_MESSAGE.SET_NAME('PSA', 'R_FCMA0033');
7810 ELSE
7811 FND_MESSAGE.SET_NAME('PSA', 'R_FCMA0032');
7812 END IF;
7813 l_funds_action := FND_MESSAGE.GET();
7814
7815 --Get the Failure/Warning message
7816 IF (l_check_flag = 'C' OR l_check_flag = 'M') THEN
7817 FND_MESSAGE.SET_NAME('PSA', 'R_FCMA0035');
7818 ELSIF (l_check_flag = 'R' OR l_check_flag = 'P') THEN
7819 FND_MESSAGE.SET_NAME('PSA', 'R_FCMA0036');
7820 ELSE
7821 FND_MESSAGE.SET_NAME('PSA', 'R_FCMA0035');
7822 END IF;
7823 l_failure_warning := FND_MESSAGE.GET();
7824
7825 --Picking the date from the database
7826 SELECT
7827 TO_CHAR(SYSDATE, 'DD-MON-YY HH24:MI')
7828 INTO
7829 l_date
7830 FROM
7831 dual;
7832
7833 --The xml reporting variables.
7834 l_header := true;
7835 l_xml_f_b_header := true;
7836 l_xml_f_l_header := true;
7837 l_xml_je_lines_header := true;
7838 l_xml_b_header := true;
7839 l_xml_f_sum_header := true;
7840 l_xml_f_bud_header := true;
7841 l_xml_f_bud_sum_header := true;
7842
7843 --Start of xml report output
7844 -- =========================== XML OUT =============================
7845 fnd_file.put_line(fnd_file.output, '<?xml version = ''1.0'' encoding = ''ISO-8859-1''?>');
7846 fnd_file.put_line(fnd_file.output, '<REPORT_ROOT>');
7847 fnd_file.put_line(fnd_file.output, ' <PARAMETERS>');
7848 fnd_file.put_line(fnd_file.output, ' <APPLICATION_NAME>'||l_application_name||'</APPLICATION_NAME>');
7849 fnd_file.put_line(fnd_file.output, ' <REPORT_NAME>'||l_report_name||'</REPORT_NAME>');
7850 fnd_file.put_line(fnd_file.output, ' <DATE>'||l_date||'</DATE>');
7851 fnd_file.put_line(fnd_file.output, ' <FUNDS_ACTION>'||l_funds_action||'</FUNDS_ACTION>');
7852 fnd_file.put_line(fnd_file.output, ' </PARAMETERS>');
7853 -- =========================== XML OUT =============================
7854
7855 BEGIN
7856 SELECT
7857 name,
7858 enable_budgetary_control_flag,
7859 enable_automatic_tax_flag,
7860 chart_of_accounts_id,
7861 currency_code
7862 INTO
7863 l_sob_name,
7864 l_budgetary_control_flag,
7865 l_automatic_tax_flag,
7866 l_coa_id,
7867 l_currency_code
7868 FROM
7869 gl_sets_of_books
7870 WHERE
7871 set_of_books_id = p_ledger_id;
7872 EXCEPTION
7873 WHEN OTHERS THEN
7874 -- =========================== FND LOG ===========================
7875 fnd_file.put_line(fnd_file.log, 'Funds C/R: Failed to fetch data from gl_sets_of_books');
7876 psa_utils.debug_other_string(g_excep_level,l_full_path,
7877 'Funds C/R: Failed to fetch data from gl_sets_of_books');
7878 -- ========================= FND LOG =============================
7879 END;
7880
7881 -- =========================== FND LOG ===========================
7882 fnd_file.put_line(fnd_file.log, 'Funds C/R: l_sob_name -> '||l_sob_name);
7883 fnd_file.put_line(fnd_file.log, 'Funds C/R: l_budgetary_control_flag -> '||l_budgetary_control_flag);
7884 fnd_file.put_line(fnd_file.log, 'Funds C/R: l_automatic_tax_flag -> '||l_automatic_tax_flag);
7885 fnd_file.put_line(fnd_file.log, 'Funds C/R: l_coa_id -> '||l_coa_id);
7886 fnd_file.put_line(fnd_file.log, 'Funds C/R: l_currency_code -> '||l_currency_code);
7887 fnd_file.put_line(fnd_file.log, 'Funds C/R: l_check_flag -> '||l_check_flag);
7888 psa_utils.debug_other_string(g_state_level, l_full_path, 'Funds C/R: l_sob_name -> '||l_sob_name);
7889 psa_utils.debug_other_string(g_state_level, l_full_path, 'Funds C/R: l_budgetary_control_flag -> '||l_budgetary_control_flag);
7890 psa_utils.debug_other_string(g_state_level, l_full_path, 'Funds C/R: l_automatic_tax_flag -> '||l_automatic_tax_flag);
7891 psa_utils.debug_other_string(g_state_level, l_full_path, 'Funds C/R: l_coa_id -> '||l_coa_id);
7892 psa_utils.debug_other_string(g_state_level, l_full_path, 'Funds C/R: l_currency_code -> '||l_currency_code);
7893 psa_utils.debug_other_string(g_state_level, l_full_path, 'Funds C/R: l_check_flag -> '||l_check_flag);
7894 -- =========================== FND LOG =============================
7895
7896 IF (l_budgetary_control_flag = 'N') THEN
7897 FND_MESSAGE.SET_NAME('PSA', 'R_FCMA0037');
7898 l_bc_not_enabled_msg := FND_MESSAGE.GET();
7899 -- =========================== FND LOG ===========================
7900 psa_utils.debug_other_string(g_state_level, l_full_path,
7901 'Funds C/R: l_budgetary_control_flag -> '||l_budgetary_control_flag); --Need to finalize the debug level
7902 fnd_file.put_line(fnd_file.log, 'Funds C/R: '||l_bc_not_enabled_msg);
7903 -- ========================= FND LOG =============================
7904
7905 -- =========================== XML OUT =============================
7906 fnd_file.put_line(fnd_file.output, '<BC_NOT_ENABLED>'||l_bc_not_enabled_msg||'</BC_NOT_ENABLED>');
7907 -- =========================== XML OUT =============================
7908 GOTO normal_exit;
7909 END IF;
7910
7911 BEGIN
7912 SELECT
7913 autopost_set_name
7914 INTO
7915 l_autopost_set_name
7916 FROM
7917 gl_automatic_posting_sets
7918 WHERE
7919 autopost_set_id = p_autopost_set_id;
7920 EXCEPTION
7921 WHEN OTHERS THEN
7922 -- =========================== FND LOG ===========================
7923 psa_utils.debug_other_string(g_excep_level,l_full_path,
7924 'Funds C/R: Failed to fetch autopost_set_name from gl_automatic_posting_sets');
7925 fnd_file.put_line(fnd_file.log, 'Funds C/R: Failed to fetch autopost_set_name from gl_automatic_posting_sets');
7926 -- ========================= FND LOG =============================
7927 END;
7928
7929 l_appl_id := 101;
7930 l_resp_id := FND_GLOBAL.resp_id;
7931 l_user_id := FND_GLOBAL.user_id;
7932
7933 -- =========================== FND LOG ===========================
7934 fnd_file.put_line(fnd_file.log, 'Funds C/R: p_autopost_set_id -> '||p_autopost_set_id);
7935 fnd_file.put_line(fnd_file.log, 'Funds C/R: l_autopost_set_name -> '||l_autopost_set_name);
7936 fnd_file.put_line(fnd_file.log, 'Funds C/R: l_appl_id -> '||l_appl_id);
7937 fnd_file.put_line(fnd_file.log, 'Funds C/R: l_resp_id -> '||l_resp_id);
7938 fnd_file.put_line(fnd_file.log, 'Funds C/R: l_user_id -> '||l_user_id);
7939 psa_utils.debug_other_string(g_state_level, l_full_path, 'Funds C/R: p_autopost_set_id -> '||p_autopost_set_id);
7940 psa_utils.debug_other_string(g_state_level, l_full_path, 'Funds C/R: l_autopost_set_name -> '||l_autopost_set_name);
7941 psa_utils.debug_other_string(g_state_level, l_full_path, 'Funds C/R: l_appl_id -> '||l_appl_id);
7942 psa_utils.debug_other_string(g_state_level, l_full_path, 'Funds C/R: l_resp_id -> '||l_resp_id);
7943 psa_utils.debug_other_string(g_state_level, l_full_path, 'Funds C/R: l_user_id -> '||l_user_id);
7944 -- =========================== FND LOG =============================
7945
7946 IF (l_automatic_tax_flag = 'Y') AND (p_check_flag = 'R') THEN
7947
7948 OPEN sel1;
7949 ELSE
7950 OPEN sel2;
7951
7952 END IF;
7953
7954 l_bc_pkts := bc_pkts_rec();
7955 l_bc_pkts_cnt := 0;
7956 l_failed_bc_pkts := bc_pkts_rec();
7957 l_failed_bc_pkts_cnt := 0;
7958
7959 LOOP
7960 IF sel1%ISOPEN THEN
7961
7962 FETCH
7963 sel1
7964 INTO
7965 l_actual_flag,
7966 l_source_name,
7967 l_period_name,
7968 l_je_batch_id,
7969 l_batch_name;
7970
7971 EXIT WHEN sel1%NOTFOUND;
7972
7973 ELSIF sel2%ISOPEN THEN
7974
7975 FETCH
7976 sel2
7977 INTO
7978 l_actual_flag,
7979 l_source_name,
7980 l_period_name,
7981 l_je_batch_id,
7982 l_batch_name;
7983
7984 EXIT WHEN sel2%NOTFOUND;
7985
7986 END IF;
7987
7988 l_packet_id := get_packet_id;
7989
7990 -- =========================== FND LOG ===========================
7991 fnd_file.put_line(fnd_file.log, 'Funds C/R: -------------------------------');
7992 fnd_file.put_line(fnd_file.log, 'Funds C/R: l_period_name -> '||l_period_name);
7993 fnd_file.put_line(fnd_file.log, 'Funds C/R: l_actual_flag -> '||l_actual_flag);
7994 fnd_file.put_line(fnd_file.log, 'Funds C/R: l_je_batch_id -> '||l_je_batch_id);
7995 fnd_file.put_line(fnd_file.log, 'Funds C/R: l_packet_id -> '||l_packet_id);
7996 fnd_file.put_line(fnd_file.log, 'Funds C/R: l_batch_name -> '||l_batch_name);
7997 fnd_file.put_line(fnd_file.log, 'Funds C/R: l_source_name -> '||l_source_name);
7998 psa_utils.debug_other_string(g_state_level, l_full_path, 'Funds C/R: -------------------------------');
7999 psa_utils.debug_other_string(g_state_level, l_full_path, 'Funds C/R: l_period_name -> '||l_period_name);
8000 psa_utils.debug_other_string(g_state_level, l_full_path, 'Funds C/R: l_actual_flag -> '||l_actual_flag);
8001 psa_utils.debug_other_string(g_state_level, l_full_path, 'Funds C/R: l_je_batch_id -> '||l_je_batch_id);
8002 psa_utils.debug_other_string(g_state_level, l_full_path, 'Funds C/R: l_packet_id -> '||l_packet_id);
8003 psa_utils.debug_other_string(g_state_level, l_full_path, 'Funds C/R: l_batch_name -> '||l_batch_name);
8004 psa_utils.debug_other_string(g_state_level, l_full_path, 'Funds C/R: l_source_name -> '||l_source_name);
8005 -- =========================== FND LOG =============================
8006
8007 -- =========================== XML OUT =============================
8008 IF (l_xml_b_header <> FALSE) THEN
8009 fnd_file.put_line(fnd_file.output, ' <LIST_G_JE_BATCH_NAME>');
8010 l_xml_b_header := FALSE;
8011 END IF;
8012 -- =========================== XML OUT =============================
8013
8014
8015 -- Get the session_id and serial# for the current session
8016 -- These columns will then be inserted in gl_bc_packets.
8017
8018 -- ====== FND LOG ======
8019 psa_utils.debug_other_string(g_state_level,l_full_path, ' BCTRL -> Invoking get_session_details() ');
8020 -- ====== FND LOG ======
8021
8022 get_session_details(l_session_id, l_serial_id);
8023
8024 -- ====== FND LOG ======
8025 psa_utils.debug_other_string(g_state_level,l_full_path, ' BCTRL -> Session_Id = '||l_session_id);
8026 psa_utils.debug_other_string(g_state_level,l_full_path, ' BCTRL -> Serial_Id = '||l_serial_id);
8027 -- ====== FND LOG ======
8028
8029 l_main_stmt := '';
8030
8031 -- =========================== FND LOG ===========================
8032 fnd_file.put_line(fnd_file.log, 'Funds C/R: l_main_stmt -> '||l_main_stmt);
8033 psa_utils.debug_other_string(g_state_level,l_full_path, 'Funds C/R: l_main_stmt -> '||l_main_stmt);
8034 -- =========================== FND LOG =============================
8035
8036 l_tmp_stmt := 'SELECT '||
8037 l_packet_id||', '||
8038 l_ledger_id||', '||''''||
8039 l_source_name||''''||
8040 ', h.je_category'||
8041 ', l.code_combination_id, '||''''||
8042 l_actual_flag|| ''''||
8043 ', ps.period_name, ps.period_year, ps.period_num, ps.quarter_num, '||
8044 'h.currency_code, decode('||''''||l_check_flag||''''||',''C'',''C'',''M'',''C'',''P'',''P'',''R'',''P''), sysdate, '||
8045 l_user_id;
8046
8047 l_action_stmt:= CASE l_actual_flag
8048 WHEN 'B' THEN ', h.budget_version_id, NULL, NULL'
8049 WHEN 'E' THEN ', NULL, h.encumbrance_type_id, NULL'
8050 WHEN 'A' THEN ', NULL, NULL, NULL'
8051 END;
8052 l_tmp_stmt := l_tmp_stmt || l_action_stmt;
8053
8054 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), '||
8055 'l.ussgl_transaction_code, '||
8056 'NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '||
8057 'NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '||
8058 'NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '||''''||
8059 l_batch_name||''''||', '||
8060 l_je_batch_id||
8061 ', l.je_header_id, l.je_line_num, '||
8062 'NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '||
8063 'NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '||
8064 'NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '||
8065 l_session_id||', '||l_serial_id||', '||l_appl_id||', '||
8066 'NULL, NULL';
8067
8068 -- =========================== FND LOG ===========================
8069 fnd_file.put_line(fnd_file.log, 'Funds C/R: l_tmp_stmt -> '||l_tmp_stmt);
8070 psa_utils.debug_other_string(g_state_level, l_full_path, 'Funds C/R: l_tmp_stmt -> '||l_tmp_stmt);
8071 -- =========================== FND LOG =============================
8072
8073 l_tmp_stmt := l_tmp_stmt || ' FROM gl_je_lines l, gl_je_headers h, ';
8074
8075 IF (l_actual_flag = 'B') THEN
8076 l_tmp_stmt := l_tmp_stmt || 'gl_budget_versions bv, ';
8077 END IF;
8078
8079 l_tmp_stmt := l_tmp_stmt || ' gl_period_statuses ps WHERE ps.application_id = '||l_appl_id||
8080 ' AND ps.ledger_id = '||l_ledger_id ||
8081 ' AND ps.period_name = '||''''||l_period_name||''''||' AND h.je_batch_id = '||l_je_batch_id ||
8082 ' AND l.je_header_id = h.je_header_id';
8083
8084 l_action_stmt:= CASE l_actual_flag
8085 WHEN 'B' THEN ' AND h.budget_version_id = bv.budget_version_id AND bv.status = ''O'''
8086 WHEN 'E' THEN ' AND (ps.closing_status = ''O'' OR ps.closing_status = ''F'')'
8087 WHEN 'A' THEN ''
8088 END;
8089
8090 l_tmp_stmt := l_tmp_stmt || l_action_stmt;
8091
8092 -- =========================== FND LOG ===========================
8093 fnd_file.put_line(fnd_file.log, 'Funds C/R: l_tmp_stmt -> '||l_tmp_stmt);
8094 psa_utils.debug_other_string(g_state_level, l_full_path, 'Funds C/R: l_tmp_stmt -> '||l_tmp_stmt);
8095 -- =========================== FND LOG =============================
8096
8097 l_main_stmt := l_main_stmt || l_tmp_stmt;
8098
8099 -- =========================== FND LOG ===========================
8100 fnd_file.put_line(fnd_file.log, 'Funds C/R: l_main_stmt -> '||l_main_stmt);
8101 fnd_file.put_line(fnd_file.log, 'Funds C/R: Executing l_main_stmt -> '||l_main_stmt||' using EXECUTE IMMEDIATE');
8102 psa_utils.debug_other_string(g_state_level, l_full_path, 'Funds C/R: l_main_stmt -> '||l_main_stmt);
8103 psa_utils.debug_other_string(g_state_level, l_full_path,
8104 'Funds C/R: Executing l_main_stmt -> '||l_main_stmt||' using EXECUTE IMMEDIATE');
8105 -- =========================== FND LOG =============================
8106
8107 EXECUTE IMMEDIATE l_main_stmt BULK COLLECT INTO l_tmp_bc_pkts;
8108
8109 l_bc_pkts.extend(l_tmp_bc_pkts.count);
8110
8111 FOR x in 1..l_tmp_bc_pkts.count
8112 LOOP
8113 l_bc_pkts_cnt := l_bc_pkts_cnt + 1;
8114 l_bc_pkts(l_bc_pkts_cnt) := l_tmp_bc_pkts(x);
8115
8116 END LOOP;
8117
8118 END LOOP; --End of loop for all the batches
8119
8120 IF NOT populate_bc_pkts (l_bc_pkts) THEN
8121 -- ====== FND LOG ======
8122 psa_utils.debug_other_string(g_error_level,l_full_path, 'Funds C/R: BCTRL -> populate_bc_pkts() failed. ');
8123 psa_utils.debug_other_string(g_error_level,l_full_path, 'Funds C/R: BCTRL -> ERROR: FATAL. ');
8124 -- ====== FND LOG ======
8125 END IF;
8126
8127 -- Invoke funds checker per packet_id
8128
8129 -- ====== FND LOG ======
8130 fnd_file.put_line(fnd_file.log, 'Funds C/R: BCTRL -> Invoking glxfck() per packet.');
8131 psa_utils.debug_other_string(g_state_level,l_full_path, 'Funds C/R: BCTRL -> Invoking glxfck() per packet.');
8132 -- ====== FND LOG ======
8133
8134 FOR x in 1..l_bc_pkts.count
8135 LOOP
8136 IF (x = 1 OR (l_bc_pkts(x).packet_id <> l_bc_pkts(x-1).packet_id)) THEN
8137
8138 -- ====== FND LOG ======
8139 fnd_file.put_line(fnd_file.log, 'Funds C/R: BCTRL -> Invoking glxfck() for packet_id '||l_bc_pkts(x).packet_id);
8140 psa_utils.debug_other_string(g_state_level,l_full_path,
8141 'Funds C/R: BCTRL -> Invoking glxfck() for packet_id '||l_bc_pkts(x).packet_id);
8142 -- ====== FND LOG ======
8143
8144 IF NOT glxfck(p_ledgerid => l_ledger_id,
8145 p_packetid => l_bc_pkts(x).packet_id,
8146 p_mode => l_check_flag,
8147 p_override => 'N',
8148 p_conc_flag => 'Y',
8149 p_user_id => l_user_id,
8150 p_user_resp_id => l_resp_id,
8151 p_calling_prog_flag => 'G',
8152 p_return_code => l_glxfck_return_code) THEN
8153 -- ====== FND LOG ======
8154 fnd_file.put_line(fnd_file.log, 'Funds C/R: BCTRL -> glxfck() failed ');
8155 psa_utils.debug_other_string(g_error_level,l_full_path, 'Funds C/R: BCTRL -> glxfck() failed ');
8156 -- ====== FND LOG ======
8157
8158 -- ============================== FND LOG =========================
8159 fnd_file.put_line(fnd_file.log, 'Funds C/R: BCTRL l_glxfck_return_code -> T ');
8160 psa_utils.debug_other_string(g_state_level,l_full_path, 'Funds C/R: BCTRL l_glxfck_return_code -> T ');
8161 -- ============================== FND LOG =========================
8162
8163 l_glxfck_return_code := 'T';
8164
8165 END IF;
8166
8167
8168 -- If the return code for this packet is Advisory, Failure, Partial,
8169 -- Fatal, we insert into failed packets table type.
8170 IF (l_glxfck_return_code <> 'S') THEN
8171
8172 -- ============================== FND LOG =========================
8173 fnd_file.put_line(fnd_file.log, 'Funds C/R: l_glxfck_return_code ->'||l_glxfck_return_code);
8174 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);
8175 psa_utils.debug_other_string(g_state_level,l_full_path,
8176 'Funds C/R: l_glxfck_return_code ->'||l_glxfck_return_code);
8177 psa_utils.debug_other_string(g_state_level,l_full_path,
8178 'Funds C/R: Inserting into l_failed_bc_pkts for packet_id->'||l_bc_pkts(x).packet_id);
8179 -- ============================== FND LOG =========================
8180
8181 l_failed_bc_pkts.extend(1);
8182 l_failed_bc_pkts_cnt := l_failed_bc_pkts_cnt + 1;
8183 l_failed_bc_pkts(l_failed_bc_pkts_cnt) := l_bc_pkts(x);
8184
8185 END IF;
8186
8187 -- =========================== FND LOG ===========================
8188 fnd_file.put_line(fnd_file.log, 'Funds C/R: l_glxfck_return_code -> '||l_glxfck_return_code);
8189 psa_utils.debug_other_string(g_state_level,l_full_path, 'Funds C/R: l_glxfck_return_code -> '||l_glxfck_return_code);
8190 -- =========================== FND LOG =============================
8191 BEGIN
8192 UPDATE
8193 gl_je_batches
8194 SET
8195 budgetary_control_status = decode(l_check_flag, 'R',
8196 decode (l_glxfck_return_code,
8197 'S', 'P',
8198 'A', 'P',
8199 'F', 'F',
8200 'P', 'F',
8201 'T', 'R', l_glxfck_return_code),
8202 'P',
8203 decode (l_glxfck_return_code,
8204 'S', 'P',
8205 'A', 'P',
8206 'F', 'F',
8207 'P', 'F',
8208 'T', 'R', l_glxfck_return_code),
8209 budgetary_control_status),
8210 packet_id = l_bc_pkts(x).packet_id
8211 WHERE
8212 je_batch_id = l_bc_pkts(x).je_batch_id;
8213 EXCEPTION
8214 WHEN OTHERS THEN
8215 -- =========================== FND LOG ===========================
8216 psa_utils.debug_other_string(g_excep_level,l_full_path,
8217 'Funds C/R: Failed to update budgetary_control_status for gl_je_batches');
8218 fnd_file.put_line(fnd_file.log,
8219 'Funds C/R: Failed to update budgetary_control_status for gl_je_batches');
8220 -- ========================= FND LOG =============================
8221 END;
8222
8223 BEGIN
8224 SELECT
8225 meaning
8226 INTO
8227 l_fmeaning
8228 FROM
8229 gl_lookups
8230 WHERE
8231 lookup_code = l_glxfck_return_code
8232 AND lookup_type = 'FUNDS_CHECK_RETURN_CODE';
8233 EXCEPTION
8234 WHEN OTHERS THEN
8235 -- =========================== FND LOG ===========================
8236 psa_utils.debug_other_string(g_excep_level,l_full_path,
8237 'Funds C/R: Failed to fetch meaning from gl_lookups');
8238 fnd_file.put_line(fnd_file.log,
8239 'Funds C/R: Failed to fetch meaning from gl_lookups');
8240 -- ========================= FND LOG =============================
8241 END;
8242
8243 -- =========================== FND LOG ===========================
8244 fnd_file.put_line(fnd_file.log, 'Funds C/R: Return Code F Meaning l_fmeaning -> '||l_fmeaning);
8245 psa_utils.debug_other_string(g_state_level,l_full_path, 'Funds C/R: Return Code F Meaning l_fmeaning -> '||l_fmeaning);
8246 -- =========================== FND LOG =============================
8247
8248 BEGIN
8249 SELECT
8250 l.meaning
8251 INTO
8252 l_jmeaning
8253 FROM
8254 gl_lookups l, gl_je_batches b
8255 WHERE
8256 l.lookup_code = b.budgetary_control_status
8257 AND l.lookup_type = 'JE_BATCH_BC_STATUS'
8258 AND b.je_batch_id = l_bc_pkts(x).je_batch_id;
8259
8260 EXCEPTION
8261 WHEN OTHERS THEN
8262 -- =========================== FND LOG ===========================
8263 psa_utils.debug_other_string(g_excep_level,l_full_path,
8264 'Funds C/R: Failed to fetch meaning from gl_je_batches');
8265 fnd_file.put_line(fnd_file.log,
8266 'Funds C/R: Failed to fetch meaning from gl_be_batches');
8267 -- ========================= FND LOG =============================
8268 END;
8269
8270 -- =========================== FND LOG ===========================
8271 fnd_file.put_line(fnd_file.log, 'Funds C/R: Return Code J Meaning l_jmeaning -> '||l_jmeaning);
8272 psa_utils.debug_other_string(g_state_level,l_full_path, 'Funds C/R: Return Code J Meaning l_jmeaning -> '||l_jmeaning);
8273 -- =========================== FND LOG =============================
8274
8275 -- =========================== XML OUT =============================
8276 fnd_file.put_line(fnd_file.output, ' <G_JE_BATCH_NAME>');
8277 fnd_file.put_line(fnd_file.output, ' <JE_BATCH_NAME>'||l_bc_pkts(x).je_batch_name||'</JE_BATCH_NAME>');
8278 fnd_file.put_line(fnd_file.output, ' <PERIOD_NAME>'||l_bc_pkts(x).period_name||'</PERIOD_NAME>');
8279 fnd_file.put_line(fnd_file.output, ' <FC_RESULT>'||l_fmeaning||'</FC_RESULT>');
8280 fnd_file.put_line(fnd_file.output, ' <JE_F_STATUS>'||l_jmeaning||'</JE_F_STATUS>');
8281 fnd_file.put_line(fnd_file.output, ' </G_JE_BATCH_NAME>');
8282 -- =========================== XML OUT =============================
8283
8284 END IF;
8285
8286 END LOOP; --End of loop for all l_bc_pkts
8287
8288 -- =========================== XML OUT =============================
8289 IF (l_xml_b_header <> TRUE) THEN
8290 fnd_file.put_line(fnd_file.output, ' </LIST_G_JE_BATCH_NAME>');
8291 END IF;
8292 -- =========================== XML OUT =============================
8293
8294 -- =========================== FND LOG ===========================
8295 fnd_file.put_line(fnd_file.log, 'Funds C/R: -------------------------------');
8296 -- =========================== FND LOG ===========================
8297
8298 --Now processing failed batches/packets.
8299 FOR x in 1..l_failed_bc_pkts.count
8300 LOOP
8301 fnd_file.put_line(fnd_file.log, 'Funds C/R: Failed Funds Check Packets Info');
8302 fnd_file.put_line(fnd_file.log, 'Funds C/R: -------------------------------');
8303 fnd_file.put_line(fnd_file.log, 'Funds C/R: Packet Id: '||
8304 l_failed_bc_pkts(x).packet_id||
8305 ' Batch Id: '||
8306 l_failed_bc_pkts(x).je_batch_id||
8307 ' Batch Name: '||l_failed_bc_pkts(x).je_batch_name);
8308
8309
8310 -- =========================== XML OUT =============================
8311 IF (l_xml_f_b_header <> FALSE) THEN
8312 fnd_file.put_line(fnd_file.output, ' <FAILED_BATCHES_EXIST>YES</FAILED_BATCHES_EXIST>');
8313 fnd_file.put_line(fnd_file.output, ' <LIST_G_FAILURE_JE_BATCH_NAME>');
8314 l_xml_f_b_header := FALSE;
8315 END IF;
8316 -- =========================== XML OUT =============================
8317
8318 -- =========================== XML OUT =============================
8319 fnd_file.put_line(fnd_file.output, ' <G_FAILURE_JE_BATCH_NAME>');
8320 fnd_file.put_line(fnd_file.output, ' <FA_FAILURES_WARNINGS>'||l_failure_warning||'</FA_FAILURES_WARNINGS>');
8321 fnd_file.put_line(fnd_file.output, ' <F_JE_BATCH_NAME>'||l_failed_bc_pkts(x).je_batch_name||'</F_JE_BATCH_NAME>');
8322 -- =========================== XML OUT =============================
8323
8324
8325 l_je_stmt := 'SELECT ';
8326 l_je_first := TRUE;
8327 FOR a in c_seg_info(l_ledger_id)
8328 LOOP
8329 IF (l_je_first <> FALSE) THEN
8330 l_je_stmt := l_je_stmt||'c.'||a.application_column_name;
8331 l_je_first := FALSE;
8332 ELSE
8333 l_je_stmt := l_je_stmt||'||''.''||'||'c.'||a.application_column_name;
8334 END IF;
8335
8336 END LOOP; --End of segments loop
8337
8338 l_je_stmt := l_je_stmt||', SUBSTRB(h.name,1,20), h.je_header_id, l.je_line_num, l.entered_dr, '||
8339 'l.entered_cr, lk.description, p.result_code, l.code_combination_id, '||
8340 'p.rowid '||
8341 'FROM gl_je_lines l, gl_je_headers h, gl_code_combinations c, '||
8342 'gl_lookups lk, gl_bc_packets p '||
8343 'WHERE p.je_batch_id = '||l_failed_bc_pkts(x).je_batch_id||
8344 ' and p.packet_id = '||l_failed_bc_pkts(x).packet_id||
8345 ' and p.ledger_id = '||l_ledger_id||
8346 ' and p.je_header_id = h.je_header_id'||
8347 ' and h.je_header_id = l.je_header_id'||
8348 ' and p.je_line_num = l.je_line_num'||
8349 ' and p.result_code = lk.lookup_code'||
8350 ' and lk.lookup_type = ''FUNDS_CHECK_RESULT_CODE'''||
8351 ' and p.code_combination_id = c.code_combination_id (+)'||
8352 ' and nvl(p.template_id,-1) = -1'||
8353 ' and p.ussgl_link_to_parent_id is null'||
8354 ' and (p.result_code like ''F%'' or p.result_code like ''P2%'') '||
8355 ' order by l.je_header_id, l.je_line_num';
8356
8357 fnd_file.put_line(fnd_file.log, 'Funds C/R: l_je_stmt -> '|| l_je_stmt);
8358
8359 l_xml_je_lines_header := TRUE;
8360
8361 OPEN l_je_lines FOR l_je_stmt;
8362
8363 LOOP
8364 FETCH l_je_lines INTO l_seg_ccid, l_je_header_name, l_je_header_id, l_je_line_num, l_entered_dr,
8365 l_entered_cr, l_line_description, l_line_result_code, l_ccid, l_rowid;
8366
8367 -- =========================== FND LOG ===========================
8368 fnd_file.put_line(fnd_file.log, 'Funds C/R: '|| l_seg_ccid||' '||l_je_header_name||' '||l_je_header_id
8369 ||' '||l_je_line_num||' '||l_entered_dr||' '||l_entered_cr||
8370 ' '||l_line_description||' '||l_line_result_code||' '||l_ccid||
8371 ' '||l_rowid);
8372 -- =========================== FND LOG ===========================
8373 EXIT WHEN l_je_lines%NOTFOUND;
8374
8375 BEGIN
8376 SELECT
8377 l.meaning
8378 INTO
8379 l_priority
8380 FROM
8381 gl_lookups l
8382 WHERE
8383 l.lookup_type = 'BC_SEVERITY_FLAG'
8384 AND l.lookup_code = upper(substr(l_line_result_code,1,1));
8385
8386 EXCEPTION
8387 WHEN OTHERS THEN
8388 -- =========================== FND LOG ===========================
8389 psa_utils.debug_other_string(g_excep_level,l_full_path, 'Funds C/R: Failed to fetch meaning from gl_lookups');
8390 fnd_file.put_line(fnd_file.log, 'Funds C/R: Failed to fetch meaning from gl_lookups');
8391 -- ========================= FND LOG =============================
8392 END;
8393
8394
8395 -- =========================== FND LOG ===========================
8396 fnd_file.put_line(fnd_file.log, 'Funds C/R: '||l_failed_bc_pkts(x).je_batch_name||
8397 l_je_header_name||' '||l_seg_ccid||' '||
8398 l_entered_dr||' '||l_entered_cr||
8399 ' '||l_priority);
8400 -- =========================== FND LOG ===========================
8401
8402 -- =========================== XML OUT =============================
8403 IF (l_xml_je_lines_header <> FALSE) THEN
8404 fnd_file.put_line(fnd_file.output, ' <F_JE_HEADER_NAME>'||l_je_header_name||'</F_JE_HEADER_NAME>');
8405 fnd_file.put_line(fnd_file.output, ' <LIST_G_JE_LINE>');
8406 l_xml_je_lines_header := FALSE;
8407 END IF;
8408 -- =========================== XML OUT =============================
8409
8410 -- =========================== XML OUT =============================
8411 fnd_file.put_line(fnd_file.output, ' <G_JE_LINE>');
8412 fnd_file.put_line(fnd_file.output, ' <JE_LINE>'||l_je_line_num||'</JE_LINE>');
8413 fnd_file.put_line(fnd_file.output, ' <ACCT_FLEX_FIELD>'||l_seg_ccid||'</ACCT_FLEX_FIELD>');
8414 fnd_file.put_line(fnd_file.output, ' <JE_DR>'||l_entered_dr||'</JE_DR>');
8415 fnd_file.put_line(fnd_file.output, ' <JE_CR>'||l_entered_cr||'</JE_CR>');
8416 fnd_file.put_line(fnd_file.output, ' <F_W>'||l_priority||'</F_W>');
8417 fnd_file.put_line(fnd_file.output, ' <G_DESC>');
8418 fnd_file.put_line(fnd_file.output, ' <DESC>'||l_line_description||'</DESC>');
8419 -- =========================== XML OUT =============================
8420
8421
8422 l_xml_f_sum_header := true;
8423
8424 --Start of Report Summary
8425 IF ( l_line_result_code = 'P22' OR
8426 l_line_result_code = 'P27' OR
8427 l_line_result_code = 'F01' OR
8428 l_line_result_code = 'F04' OR
8429 l_line_result_code = 'F11' OR
8430 l_line_result_code = 'F14') THEN
8431
8432 l_je_seg_stmt := 'SELECT distinct ';
8433 l_je_first := TRUE;
8434 FOR a in c_seg_info(l_ledger_id)
8435 LOOP
8436 IF (l_je_first <> FALSE) THEN
8437 l_je_seg_stmt := l_je_seg_stmt||'c.'||a.application_column_name;
8438 l_je_first := FALSE;
8439 ELSE
8440 l_je_seg_stmt := l_je_seg_stmt||'||''.''||'||'c.'||a.application_column_name;
8441 END IF;
8442
8443 END LOOP; --End of segments loop
8444
8445 l_je_seg_stmt := l_je_seg_stmt||' FROM gl_code_combinations c, gl_account_hierarchies h, '||
8446 ' gl_bc_packets p where h.detail_code_combination_id = '||
8447 l_ccid||' and p.code_combination_id = h.summary_code_combination_id '||
8448 ' and p.packet_id = '||l_failed_bc_pkts(x).packet_id||
8449 ' and c.code_combination_id = p.code_combination_id';
8450
8451 fnd_file.put_line(fnd_file.log, 'Funds C/R: l_je_seg_stmt -> '||l_je_seg_stmt);
8452
8453 OPEN l_je_sum_lines for l_je_seg_stmt;
8454 LOOP
8455 FETCH l_je_sum_lines into l_je_sum_flex;
8456 EXIT WHEN l_je_sum_lines%NOTFOUND;
8457
8458 -- =========================== XML OUT =============================
8459 IF (l_xml_f_sum_header <> FALSE) THEN
8460 fnd_file.put_line(fnd_file.output, ' <LIST_DESC_SUM>');
8461 fnd_file.put_line(fnd_file.output, ' <DESC_SUM_EXISTS>YES</DESC_SUM_EXISTS>');
8462 l_xml_f_sum_header := FALSE;
8463 END IF;
8464 -- =========================== XML OUT =============================
8465
8466 fnd_file.put_line(fnd_file.log, 'Funds C/R: l_je_sum_flex -> '||l_je_sum_flex);
8467
8468 -- =========================== XML OUT =============================
8469 fnd_file.put_line(fnd_file.output, ' <DESC_SUM>');
8470 fnd_file.put_line(fnd_file.output, ' <SUM_FLEX>'||l_je_sum_flex||'</SUM_FLEX>');
8471 fnd_file.put_line(fnd_file.output, ' </DESC_SUM>');
8472 -- =========================== XML OUT =============================
8473
8474 END LOOP; --End of l_je_sum_lines cursor
8475
8476 CLOSE l_je_sum_lines;
8477 -- =========================== XML OUT =============================
8478 IF (l_xml_f_sum_header <> TRUE) THEN
8479 fnd_file.put_line(fnd_file.output, ' </LIST_DESC_SUM>');
8480 l_xml_f_sum_header := TRUE;
8481 END IF;
8482 -- =========================== XML OUT =============================
8483
8484
8485 END IF; --Summary Report End
8486
8487 --Budgetary Report Start
8488 l_xml_f_bud_header := true;
8489 l_je_bud_stmt := 'SELECT ';
8490 l_je_first := TRUE;
8491 FOR a in c_seg_info(l_ledger_id)
8492 LOOP
8493 IF (l_je_first <> FALSE) THEN
8494 l_je_bud_stmt := l_je_bud_stmt||'c.'||a.application_column_name;
8495 l_je_first := FALSE;
8496 ELSE
8497 l_je_bud_stmt := l_je_bud_stmt||'||''.''||'||'c.'||a.application_column_name;
8498 END IF;
8499
8500 END LOOP; --End of segments loop
8501
8502 BEGIN
8503 SELECT
8504 nvl(ussgl_parent_id, 0)
8505 INTO
8506 l_ussgl_parent_id
8507 FROM
8508 gl_bc_packets
8509 WHERE
8510 rowid = l_rowid;
8511 EXCEPTION
8512 WHEN OTHERS THEN
8513 -- =========================== FND LOG ===========================
8514 psa_utils.debug_other_string(g_excep_level,l_full_path, 'Funds C/R: Failed to fetch ussgl_parent_id from gl_bc_packets');
8515 fnd_file.put_line(fnd_file.log, 'Funds C/R: Failed to fetch ussgl_parent_id from gl_bc_packets');
8516 -- ========================= FND LOG =============================
8517 END;
8518
8519 l_je_bud_stmt := l_je_bud_stmt||' , p.entered_dr, p.entered_cr, p.result_code, l.description, '||
8520 ' c.code_combination_id FROM gl_code_combinations c, gl_bc_packets p, '||
8521 ' gl_lookups l WHERE p.ussgl_link_to_parent_id = '||l_ussgl_parent_id||
8522 ' and p.packet_id = '||l_failed_bc_pkts(x).packet_id||
8523 ' and c.code_combination_id = p.code_combination_id'||
8524 ' and p.result_code between ''F00'' AND ''F30'' and '||
8525 ' p.result_code = l.lookup_code and l.lookup_type = ''FUNDS_CHECK_RESULT_CODE'' '||
8526 ' order by p.code_combination_id';
8527
8528 fnd_file.put_line(fnd_file.log, 'Funds C/R: l_je_bud_stmt -> '||l_je_bud_stmt);
8529
8530 OPEN l_je_bud_lines for l_je_bud_stmt;
8531 LOOP
8532 FETCH l_je_bud_lines into l_je_bud_flex, l_je_bud_dr, l_je_bud_cr, l_je_bud_result_code,
8533 l_je_bud_desc, l_je_bud_ccid;
8534
8535 EXIT WHEN l_je_bud_lines%NOTFOUND;
8536 fnd_file.put_line(fnd_file.log, 'Funds C/R: l_je_bud_flex -> '||l_je_bud_flex
8537 ||'l_je_bud_dr ->' ||l_je_bud_dr
8538 ||'l_je_bud_cr ->' ||l_je_bud_cr
8539 ||'l_je_bud_result_code ->' ||l_je_bud_result_code
8540 ||'l_je_bud_desc ->' ||l_je_bud_desc
8541 ||'l_je_bud_ccid ->' ||l_je_bud_ccid
8542 );
8543
8544 -- =========================== XML OUT =============================
8545 IF (l_xml_f_bud_header <> FALSE) THEN
8546 fnd_file.put_line(fnd_file.output, ' <LIST_DESC_BUD>');
8547 fnd_file.put_line(fnd_file.output, ' <DESC_BUD_EXISTS>YES</DESC_BUD_EXISTS>');
8548 l_xml_f_bud_header := FALSE;
8549 END IF;
8550 -- =========================== XML OUT =============================
8551
8552 -- =========================== XML OUT =============================
8553 fnd_file.put_line(fnd_file.output, ' <G_DESC_BUD>');
8554 fnd_file.put_line(fnd_file.output, ' <DESC_BUD_FLEX>'||l_je_bud_flex||'</DESC_BUD_FLEX>');
8555 fnd_file.put_line(fnd_file.output, ' <DESC_BUD_DR>'||l_je_bud_dr||'</DESC_BUD_DR>');
8556 fnd_file.put_line(fnd_file.output, ' <DESC_BUD_CR>'||l_je_bud_cr||'</DESC_BUD_CR>');
8557 fnd_file.put_line(fnd_file.output, ' <DESC_BUD_DESC>'||l_je_bud_desc||'</DESC_BUD_DESC>');
8558 fnd_file.put_line(fnd_file.output, ' </G_DESC_BUD>');
8559 -- =========================== XML OUT =============================
8560
8561 l_xml_f_bud_sum_header := true;
8562
8563 IF ( l_je_bud_result_code = 'F11' OR
8564 l_je_bud_result_code = 'F14' OR
8565 l_je_bud_result_code = 'F01' OR
8566 l_je_bud_result_code = 'F04')THEN
8567
8568 --Summary Report with the l_je_bud_ccid
8569 l_je_bud_seg_stmt := 'SELECT distinct ';
8570 l_je_first := TRUE;
8571 FOR a in c_seg_info(l_ledger_id)
8572 LOOP
8573 IF (l_je_first <> FALSE) THEN
8574 l_je_bud_seg_stmt := l_je_bud_seg_stmt||'c.'||a.application_column_name;
8575 l_je_first := FALSE;
8576 ELSE
8577 l_je_bud_seg_stmt := l_je_bud_seg_stmt||'||''.''||'||'c.'||a.application_column_name;
8578 END IF;
8579
8580 END LOOP; --End of segments loop
8581
8582 l_je_bud_seg_stmt := l_je_bud_seg_stmt||' FROM gl_code_combinations c, gl_account_hierarchies h, '||
8583 ' gl_bc_packets p where h.detail_code_combination_id = '||
8584 l_je_bud_ccid||' and p.code_combination_id = h.summary_code_combination_id '||
8585 ' and p.packet_id = '||l_failed_bc_pkts(x).packet_id||
8586 ' and c.code_combination_id = p.code_combination_id';
8587
8588 fnd_file.put_line(fnd_file.log, 'Funds C/R: l_je_bud_seg_stmt -> '||l_je_bud_seg_stmt);
8589
8590 OPEN l_je_sum_lines for l_je_bud_seg_stmt;
8591 LOOP
8592 FETCH l_je_sum_lines into l_je_bud_sum_flex;
8593 EXIT WHEN l_je_sum_lines%NOTFOUND;
8594 fnd_file.put_line(fnd_file.log, 'Funds C/R: l_je_bud_sum_flex -> '||l_je_bud_sum_flex);
8595
8596 -- =========================== XML OUT =============================
8597 IF (l_xml_f_bud_sum_header <> FALSE) THEN
8598 fnd_file.put_line(fnd_file.output, ' <LIST_DESC_BUD_SUM>');
8599 fnd_file.put_line(fnd_file.output, ' <DESC_BUD_SUM_EXISTS>YES</DESC_BUD_SUM_EXISTS>');
8600 l_xml_f_bud_sum_header := FALSE;
8601 END IF;
8602 -- =========================== XML OUT =============================
8603 -- =========================== XML OUT =============================
8604 fnd_file.put_line(fnd_file.output, ' <DESC_BUD_SUM>');
8605 fnd_file.put_line(fnd_file.output, ' <BUD_SUM_FLEX>'||l_je_bud_sum_flex||'</BUD_SUM_FLEX>');
8606 fnd_file.put_line(fnd_file.output, ' </DESC_BUD_SUM>');
8607 -- =========================== XML OUT =============================
8608
8609
8610
8611 END LOOP; --End of l_je_sum_lines cursor
8612 CLOSE l_je_sum_lines;
8613 -- =========================== XML OUT =============================
8614 IF (l_xml_f_bud_sum_header <> TRUE) THEN
8615 fnd_file.put_line(fnd_file.output, ' </LIST_DESC_BUD_SUM>');
8616 l_xml_f_bud_sum_header := TRUE;
8617 END IF;
8618 -- =========================== XML OUT =============================
8619
8620
8621 END IF; --End Report Summary
8622
8623 END LOOP; --End of l_je_bud_lines cursor
8624
8625 -- =========================== XML OUT =============================
8626 IF (l_xml_f_bud_header <> TRUE) THEN
8627 fnd_file.put_line(fnd_file.output, ' </LIST_DESC_BUD>');
8628 l_xml_f_bud_header := TRUE;
8629 END IF;
8630 -- =========================== XML OUT =============================
8631
8632 CLOSE l_je_bud_lines;
8633
8634 -- =========================== XML OUT =============================
8635 fnd_file.put_line(fnd_file.output, ' </G_DESC>');
8636 fnd_file.put_line(fnd_file.output, ' </G_JE_LINE>');
8637 -- =========================== XML OUT =============================
8638
8639
8640 END LOOP;
8641
8642 CLOSE l_je_lines;
8643 -- =========================== XML OUT =============================
8644 IF (l_xml_je_lines_header <> TRUE) THEN
8645 fnd_file.put_line(fnd_file.output, ' </LIST_G_JE_LINE>');
8646 END IF;
8647 fnd_file.put_line(fnd_file.output, ' </G_FAILURE_JE_BATCH_NAME>');
8648 -- =========================== XML OUT =============================
8649
8650 END LOOP; -- End of failed pkts loop
8651 -- =========================== XML OUT =============================
8652 IF (l_xml_f_b_header <> TRUE) THEN
8653 fnd_file.put_line(fnd_file.output, ' </LIST_G_FAILURE_JE_BATCH_NAME>');
8654 END IF;
8655 -- =========================== XML OUT =============================
8656
8657 <<NORMAL_EXIT>>
8658 -- =========================== XML OUT =============================
8659 fnd_file.put_line(fnd_file.output, '</REPORT_ROOT>');
8660 -- =========================== XML OUT =============================
8661
8662
8663 IF sel1%ISOPEN THEN
8664 CLOSE sel1;
8665
8666 ELSIF sel2%ISOPEN THEN
8667 CLOSE sel2;
8668
8669 END IF;
8670
8671 COMMIT;
8672
8673 END;
8674
8675
8676 /*=======================================================================+
8677 | Function : GET_DEBUG |
8678 | Description : Returns value stored in g_debug variable. |
8679 | This was used by some sub-ledger team in 11i. Not sure |
8680 | if its still applicable for R12. Will check and remove. |
8681 +=======================================================================*/
8682 FUNCTION get_debug RETURN VARCHAR2 IS
8683 BEGIN
8684 return g_debug;
8685 END get_debug;
8686
8687
8688 /*=======================================================================+
8689 | Function : GLSIBC |
8690 | Description : Procedure added by Abhishek |
8691 +=======================================================================*/
8692
8693 PROCEDURE glsibc (p_last_updated_by NUMBER,
8694 p_new_template_id NUMBER,
8695 p_ledger_id NUMBER) IS
8696
8697 l_full_path VARCHAR2(100);
8698 BEGIN
8699 l_full_path := g_path||'Glsibc';
8700
8701 INSERT INTO GL_BC_PACKETS
8702 (packet_id,
8703 ledger_id,
8704 je_source_name,
8705 je_category_name,
8706 code_combination_id,
8707 actual_flag,
8708 period_name,
8709 period_year,
8710 period_num,
8711 quarter_num,
8712 currency_code,
8713 status_code,
8714 last_update_date,
8715 last_updated_by,
8716 budget_version_id,
8717 encumbrance_type_id,
8718 template_id,
8719 entered_dr,
8720 entered_cr,
8721 accounted_dr,
8722 accounted_cr,
8723 funding_budget_version_id,
8724 funds_check_level_code,
8725 amount_type,
8726 boundary_code,
8727 dr_cr_code,
8728 account_category_code,
8729 effect_on_funds_code,
8730 result_code,
8731 session_id,
8732 serial_id,
8733 application_id)
8734 SELECT
8735 min(BP.packet_id),
8736 min(BP.ledger_id),
8737 min(BP.je_source_name),
8738 min(BP.je_category_name),
8739 min(AH.summary_code_combination_id),
8740 min(BP.actual_flag),
8741 min(BP.period_name),
8742 min(BP.period_year),
8743 min(BP.period_num),
8744 min(BP.quarter_num),
8745 min(BP.currency_code),
8746 'A', /* approved */
8747 SYSDATE,
8748 p_last_updated_by,
8749 min(decode(BP.actual_flag, 'B', BP.budget_version_id, NULL)),
8750 min(decode(BP.actual_flag, 'E', BP.encumbrance_type_id, NULL)),
8751 p_new_template_id,
8752 sum(nvl(BP.entered_dr,0)),
8753 sum(nvl(BP.entered_cr,0)),
8754 sum(nvl(BP.accounted_dr,0)),
8755 sum(nvl(BP.accounted_cr,0)),
8756 SB.funding_budget_version_id,
8757 SB.funds_check_level_code,
8758 SB.amount_type,
8759 SB.boundary_code,
8760 SB.dr_cr_code,
8761 min(ST.account_category_code),
8762 decode(
8763 decode(min(BP.actual_flag) || SB.dr_cr_code ||
8764 min(ST.account_category_code),
8765 'BCP', 'dec',
8766 'ADP', 'dec',
8767 'EDP', 'dec',
8768 'ACB', 'dec',
8769 'inc'),
8770 'dec', /* +ve net dr => decreasing fa */
8771 decode(sign(sum(nvl(BP.accounted_dr,0) - nvl(BP.accounted_cr,0))),
8772 1, 'D', 'I'),
8773 'inc', /* +ve net dr => increasing fa */
8774 decode(sign(sum(nvl(BP.accounted_dr,0) - nvl(BP.accounted_cr,0))),
8775 -1, 'D', 'I')),
8776 'P04', /* P04 - This summary transaction generated does not */
8777 /* require funds check */
8778 min(BP.session_id),
8779 min(BP.serial_id),
8780 min(BP.application_id)
8781 FROM
8782 GL_ACCOUNT_HIERARCHIES AH,
8783 GL_BC_PACKETS BP,
8784 GL_BC_PACKET_ARRIVAL_ORDER AO,
8785 GL_SUMMARY_TEMPLATES ST,
8786 GL_SUMMARY_BC_OPTIONS SB,
8787 GL_BUDGETS B,
8788 GL_BUDGET_VERSIONS BV,
8789 GL_PERIOD_STATUSES PS
8790
8791 WHERE
8792 AH.ledger_id = p_ledger_id
8793 AND AH.detail_code_combination_id = BP.code_combination_id
8794 AND AH.template_id = p_new_template_id
8795 AND BP.status_code = 'A'
8796 AND BP.ledger_id = p_ledger_id
8797 AND BP.template_id IS NULL
8798 AND BP.packet_id = AO.packet_id
8799 AND BP.account_category_code = ST.account_category_code
8800 AND nvl(BP.budget_version_id, -1) = decode(BP.actual_flag, 'B',
8801 SB.funding_budget_version_id, -1)
8802 AND AO.ledger_id = p_ledger_id
8803 AND AO.affect_funds_flag = 'Y'
8804 AND ST.template_id = p_new_template_id
8805 AND SB.template_id = ST.template_id
8806 AND SB.funding_budget_version_id = BV.budget_version_id
8807 AND BV.budget_name = B.budget_name
8808 AND PS.application_id = 101
8809 AND PS.ledger_id = p_ledger_id
8810 AND PS.period_name = BP.period_name
8811 AND PS.effective_period_num >= (SELECT P1.effective_period_num
8812 FROM GL_PERIOD_STATUSES P1
8813 WHERE P1.period_name = B.first_valid_period_name
8814 AND P1.application_id = 101
8815 AND P1.ledger_id = p_ledger_id)
8816 AND PS.effective_period_num <= (SELECT P2.effective_period_num
8817 FROM GL_PERIOD_STATUSES P2
8818 WHERE P2.period_name = B.last_valid_period_name
8819 AND P2.application_id = 101
8820 AND P2.ledger_id = p_ledger_id)
8821 GROUP BY
8822 BP.packet_id,
8823 AH.summary_code_combination_id,
8824 BP.actual_flag,
8825 BP.period_name,
8826 BP.currency_code,
8827 BP.je_source_name,
8828 BP.je_category_name,
8829 BP.budget_version_id,
8830 BP.encumbrance_type_id,
8831 SB.funding_budget_version_id,
8832 SB.funds_check_level_code,
8833 SB.amount_type,
8834 SB.boundary_code,
8835 SB.dr_cr_code
8836 HAVING
8837 sum(nvl(BP.accounted_dr,0)-nvl(BP.accounted_cr,0)) <> 0;
8838
8839 -- =========================== FND LOG ===========================
8840 psa_utils.debug_other_string(g_state_level,l_full_path, ' Insert GL_BC_PACKETS -> ' || SQL%ROWCOUNT);
8841 -- ========================= FND LOG =============================
8842
8843 END glsibc;
8844
8845 /*=======================================================================+
8846 | Function : GLSFBC |
8847 | Description : Procedure added by Abhishek |
8848 +=======================================================================*/
8849
8850 PROCEDURE glsfbc (p_curr_temp_id IN NUMBER,
8851 p_ledger_id IN NUMBER,
8852 p_last_updated_by IN NUMBER) IS
8853
8854 l_full_path VARCHAR2(100);
8855 BEGIN
8856 l_full_path := g_path||'Glsfbc';
8857
8858 -- =========================== FND LOG ===========================
8859 fnd_file.put_line(fnd_file.log, 'p_curr_temp_id = '||p_curr_temp_id);
8860 fnd_file.put_line(fnd_file.log, 'p_ledger_id = '||p_ledger_id);
8861 fnd_file.put_line(fnd_file.log, 'SHRD0114 ' || '1 ' || 'stmt ' || 'Inserting into GL_BC_PACKETS ...');
8862 -- =========================== FND LOG =============================
8863
8864 INSERT INTO GL_BC_PACKETS
8865 (packet_id,
8866 ledger_id,
8867 je_source_name,
8868 je_category_name,
8869 code_combination_id,
8870 actual_flag,
8871 period_name,
8872 period_year,
8873 period_num,
8874 quarter_num,
8875 currency_code,
8876 status_code,
8877 last_update_date,
8878 last_updated_by,
8879 budget_version_id,
8880 encumbrance_type_id,
8881 template_id,
8882 entered_dr,
8883 entered_cr,
8884 accounted_dr,
8885 accounted_cr,
8886 funding_budget_version_id,
8887 funds_check_level_code,
8888 amount_type,
8889 boundary_code,
8890 dr_cr_code,
8891 account_category_code,
8892 effect_on_funds_code,
8893 result_code,
8894 session_id,
8895 serial_id,
8896 application_id)
8897 SELECT
8898 BP.packet_id,
8899 min(BP.ledger_id),
8900 BP.je_source_name,
8901 BP.je_category_name,
8902 AH.summary_code_combination_id,
8903 BP.actual_flag,
8904 BP.period_name,
8905 min(BP.period_year),
8906 min(BP.period_num),
8907 min(BP.quarter_num),
8908 BP.currency_code,
8909 'A', /* approved */
8910 SYSDATE,
8911 p_last_updated_by,
8912 min(decode(BP.actual_flag, 'B',
8913 BP.budget_version_id, NULL)),
8914 min(decode(BP.actual_flag, 'E',
8915 BP.encumbrance_type_id, NULL)),
8916 p_curr_temp_id,
8917 0, 0, 0, 0,
8918 SB.funding_budget_version_id,
8919 SB.funds_check_level_code,
8920 SB.amount_type,
8921 SB.boundary_code,
8922 SB.dr_cr_code,
8923 min(ST.account_category_code),
8924 'I',
8925 'P04', /* P04 - This summary transaction generated */
8926 /* does not require funds check */
8927 min(BP.session_id),
8928 min(BP.serial_id),
8929 min(BP.application_id)
8930 FROM
8931 GL_ACCOUNT_HIERARCHIES AH,
8932 GL_BC_PACKETS BP,
8933 GL_BC_PACKET_ARRIVAL_ORDER AO,
8934 GL_SUMMARY_TEMPLATES ST,
8935 GL_SUMMARY_BC_OPTIONS SB,
8936 GL_BUDGETS B,
8937 GL_BUDGET_VERSIONS BV,
8938 GL_PERIOD_STATUSES PS
8939 WHERE AH.ledger_id = p_ledger_id
8940 AND AH.detail_code_combination_id = BP.code_combination_id
8941 AND AH.template_id = p_curr_temp_id
8942 AND BP.status_code = 'A'
8943 AND BP.ledger_id = p_ledger_id
8944 AND BP.template_id IS NULL
8945 AND BP.packet_id = AO.packet_id
8946 AND BP.account_category_code = ST.account_category_code
8947 AND nvl(BP.budget_version_id, -1) =
8948 decode(BP.actual_flag, 'B',
8949 SB.funding_budget_version_id, -1)
8950 AND AO.ledger_id = p_ledger_id
8951 AND AO.affect_funds_flag = 'Y'
8952 AND ST.template_id = p_curr_temp_id
8953 AND NOT EXISTS
8954 ( Select 'Y'
8955 From GL_BC_PACKETS BP2
8956 Where BP2.ledger_id = p_ledger_id
8957 And BP2.template_id = p_curr_temp_id
8958 And BP2.code_combination_id = AH.summary_code_combination_id
8959 And BP2.packet_id = BP.packet_id
8960 And BP2.actual_flag = BP.actual_flag
8961 And BP2.period_name = BP.period_name
8962 And BP2.currency_code = BP.currency_code
8963 And BP2.je_source_name = BP.je_source_name
8964 And BP2.je_category_name = BP.je_category_name
8965 And nvl(BP2.encumbrance_type_id,-1) = nvl(BP.encumbrance_type_id,-1)
8966 And nvl(BP2.budget_version_id,-1) = nvl(BP.budget_version_id,-1))
8967 AND SB.template_id = p_curr_temp_id
8968 AND SB.funding_budget_version_id = BV.budget_version_id
8969 AND BV.budget_name = B.budget_name
8970 AND PS.application_id = 101
8971 AND PS.ledger_id = p_ledger_id
8972 AND PS.period_name = BP.period_name
8973 AND PS.effective_period_num >=
8974 ( Select P1.effective_period_num
8975 From GL_PERIOD_STATUSES P1
8976 Where P1.period_name = B.first_valid_period_name
8977 And P1.application_id = 101
8978 And P1.ledger_id = p_ledger_id)
8979 AND PS.effective_period_num <=
8980 ( Select P2.effective_period_num
8981 From GL_PERIOD_STATUSES P2
8982 Where P2.period_name = B.last_valid_period_name
8983 And P2.application_id = 101
8984 And P2.ledger_id = p_ledger_id)
8985 GROUP BY
8986 BP.packet_id,
8987 AH.summary_code_combination_id,
8988 BP.actual_flag,
8989 BP.period_name,
8990 BP.currency_code,
8991 BP.je_source_name,
8992 BP.je_category_name,
8993 BP.budget_version_id,
8994 BP.encumbrance_type_id,
8995 SB.funding_budget_version_id,
8996 SB.funds_check_level_code,
8997 SB.amount_type,
8998 SB.boundary_code,
8999 SB.dr_cr_code
9000
9001 HAVING
9002 sum(nvl(BP.accounted_dr,0)-nvl(BP.accounted_cr,0)) <> 0;
9003
9004 -- =========================== FND LOG ===========================
9005 psa_utils.debug_other_string(g_state_level,l_full_path, ' Insert GL_BC_PACKETS -> ' || SQL%ROWCOUNT);
9006 -- ========================= FND LOG =============================
9007
9008
9009 -- =========================== FND LOG ===========================
9010 fnd_file.put_line(fnd_file.log, 'GL_BC_PACKETS');
9011 fnd_file.put_line(fnd_file.log, 'SHRD0114 ' || '1 ' || 'stmt ' || 'Updating GL_BC_PACKETS ...');
9012 -- =========================== FND LOG =============================
9013
9014 UPDATE gl_bc_packets bp2
9015 SET (entered_dr, entered_cr, accounted_dr, accounted_cr,
9016 effect_on_funds_code) =
9017 (SELECT SUM (NVL (bp.entered_dr, 0)), SUM (NVL (bp.entered_cr,0)),
9018 SUM (NVL (bp.accounted_dr, 0)),
9019 SUM (NVL (bp.accounted_cr, 0)),
9020 DECODE (DECODE ( MIN (bp.actual_flag)
9021 || MIN(sb.dr_cr_code)
9022 || MIN (st.account_category_code),
9023 'BCP', 'dec',
9024 'ADP', 'dec',
9025 'EDP', 'dec',
9026 'ACB', 'dec',
9027 'inc'
9028 ),
9029 'dec', /* +ve net dr => decreasing fa */
9030 DECODE (SIGN (SUM ( NVL (bp.accounted_dr, 0)
9031 - NVL (bp.accounted_cr, 0)
9032 )
9033 ),
9034 1, 'D',
9035 'I'
9036 ),
9037 'inc', /* +ve net dr => increasing fa */
9038 DECODE (SIGN (SUM ( NVL (bp.accounted_dr, 0)
9039 - NVL (bp.accounted_cr, 0)
9040 )
9041 ),
9042 -1, 'D',
9043 'I'
9044 )
9045 )
9046 FROM gl_bc_packets bp,
9047 gl_account_hierarchies ah,
9048 gl_bc_packet_arrival_order ao,
9049 gl_summary_templates st,
9050 gl_summary_bc_options sb,
9051 gl_budgets b,
9052 gl_budget_versions bv,
9053 gl_period_statuses ps
9054 WHERE ah.ledger_id = p_ledger_id
9055 AND ah.template_id = p_curr_temp_id
9056 AND ah.summary_code_combination_id = bp2.code_combination_id
9057 AND st.template_id = p_curr_temp_id
9058 AND bp.status_code = 'A'
9059 AND bp.ledger_id = p_ledger_id
9060 AND bp.template_id IS NULL
9061 AND bp.code_combination_id = ah.detail_code_combination_id
9062 AND bp.account_category_code = st.account_category_code
9063 AND bp.packet_id = bp2.packet_id
9064 AND bp.actual_flag = bp2.actual_flag
9065 AND bp.period_name = bp2.period_name
9066 AND bp.currency_code = bp2.currency_code
9067 AND bp.je_source_name = bp2.je_source_name
9068 AND bp.je_category_name = bp2.je_category_name
9069 AND nvl(BP.encumbrance_type_id, -1) = nvl(BP2.encumbrance_type_id, -1)
9070 AND nvl(BP.budget_version_id,-1) = nvl(BP2.budget_version_id,-1)
9071 AND sb.template_id = p_curr_temp_id
9072 AND sb.funding_budget_version_id = bv.budget_version_id
9073 AND bv.budget_name = b.budget_name
9074 AND ps.application_id = 101
9075 AND ps.ledger_id = p_ledger_id
9076 AND ps.period_name = bp.period_name
9077 AND ps.effective_period_num >=
9078 (SELECT p1.effective_period_num
9079 FROM gl_period_statuses p1
9080 WHERE p1.period_name = b.first_valid_period_name
9081 AND p1.application_id = 101
9082 AND p1.ledger_id = p_ledger_id)
9083 AND ps.effective_period_num <=
9084 (SELECT p2.effective_period_num
9085 FROM gl_period_statuses p2
9086 WHERE p2.period_name = b.last_valid_period_name
9087 AND p2.application_id = 101
9088 AND p2.ledger_id = p_ledger_id)
9089 AND NVL (bp.budget_version_id, -1) =
9090 DECODE (bp.actual_flag,
9091 'B', sb.funding_budget_version_id,
9092 -1
9093 )
9094 AND ao.ledger_id = p_ledger_id
9095 AND ao.affect_funds_flag = 'Y'
9096 AND ao.packet_id = bp2.packet_id)
9097 WHERE bp2.ledger_id = p_ledger_id
9098 AND bp2.template_id = p_curr_temp_id
9099 AND bp2.code_combination_id IN (SELECT code_combination_id
9100 FROM gl_code_combinations
9101 WHERE template_id = p_curr_temp_id);
9102
9103 -- =========================== FND LOG ===========================
9104 psa_utils.debug_other_string(g_state_level,l_full_path, ' Update GL_BC_PACKETS -> ' || SQL%ROWCOUNT);
9105 -- ========================= FND LOG =============================
9106
9107
9108
9109 /*---------------------------------------------------+
9110 | The Delete statement will be executed here ALWAYS |
9111 +---------------------------------------------------*/
9112
9113 -- =========================== FND LOG ===========================
9114 fnd_file.put_line(fnd_file.log, 'SHRD0114 ' || '1 ' || 'stmt ' || 'Deleting from GL_BC_PACKETS ...');
9115 -- =========================== FND LOG =============================
9116
9117
9118 DELETE FROM gl_bc_packets bp
9119 WHERE bp.ledger_id = p_ledger_id
9120 AND bp.template_id = p_curr_temp_id
9121 AND bp.packet_id IN (
9122 SELECT ao.packet_id
9123 FROM gl_bc_packet_arrival_order ao
9124 WHERE ao.ledger_id = p_ledger_id
9125 AND ao.affect_funds_flag = 'Y')
9126 AND NOT EXISTS (
9127 SELECT 'Y'
9128 FROM gl_account_hierarchies ah
9129 WHERE ah.ledger_id = p_ledger_id
9130 AND ah.template_id = p_curr_temp_id
9131 AND ah.summary_code_combination_id = bp.code_combination_id);
9132
9133 -- =========================== FND LOG ===========================
9134 psa_utils.debug_other_string(g_state_level,l_full_path, ' Delete GL_BC_PACKETS -> ' || SQL%ROWCOUNT);
9135 -- ========================= FND LOG =============================
9136
9137 -- =========================== FND LOG ===========================
9138 fnd_file.put_line(fnd_file.log, 'GL_BC_PACKETS');
9139 -- =========================== FND LOG =============================
9140
9141 END glsfbc;
9142
9143 /*=======================================================================+
9144 | Function : GET_SESSION_DETAILS |
9145 | Description : Returns the session_id and serial_id of current session |
9146 +=======================================================================*/
9147
9148 PROCEDURE get_session_details(x_session_id OUT NOCOPY NUMBER,
9149 x_serial_id OUT NOCOPY NUMBER) IS
9150
9151 l_full_path VARCHAR2(100);
9152 BEGIN
9153
9154 l_full_path := g_path||'get_session_details';
9155
9156 select s.audsid, s.serial# into x_session_id, x_serial_id
9157 from v$session s, v$process p
9158 where s.paddr = p.addr
9159 and s.audsid = USERENV('SESSIONID');
9160
9161 -- =========================== FND LOG ===========================
9162 psa_utils.debug_other_string(g_state_level,l_full_path, ' x_session_id -> ' || x_session_id);
9163 psa_utils.debug_other_string(g_state_level,l_full_path, ' x_serial_id -> ' || x_serial_id);
9164 -- ========================= FND LOG =============================
9165
9166 EXCEPTION
9167 WHEN others THEN
9168 -- ========================= FND LOG ===========================
9169 psa_utils.debug_other_string(g_excep_level,l_full_path, ' EXCEPTION WHEN OTHERS ' || SQLERRM);
9170 psa_utils.debug_other_string(g_excep_level,l_full_path, ' raise');
9171 -- ========================= FND LOG ===========================
9172
9173 raise;
9174 END get_session_details;
9175
9176
9177 /*=======================================================================+
9178 | Function : POPULATE_GROUP_ID |
9179 | Description : Invoked by SLA during transfer to GL |
9180 +=======================================================================*/
9181
9182 PROCEDURE populate_group_id (p_grp_id IN NUMBER,
9183 p_application_id IN NUMBER,
9184 p_je_batch_name IN VARCHAR2 DEFAULT NULL) IS
9185 l_full_path VARCHAR2(100);
9186 BEGIN
9187 l_full_path := g_path||'Populate_Group_Id';
9188
9189 UPDATE gl_bc_packets
9190 SET group_id = p_grp_id,
9191 je_batch_name = p_je_batch_name
9192 WHERE ae_header_id IN (SELECT ae_header_id
9193 FROM xla_ae_headers
9194 WHERE group_id = p_grp_id
9195 and application_id = p_application_id);
9196
9197 -- =========================== FND LOG ===========================
9198 psa_utils.debug_other_string(g_state_level,l_full_path, ' Update GL_BC_PACKETS -> ' || SQL%ROWCOUNT);
9199 -- ========================= FND LOG =============================
9200
9201 END populate_group_id;
9202
9203
9204 /*===========================================================================================+
9205 | Function : DEBUG_XLA_INSERT |
9206 | Description : This Procedure inserts data from global temporary SLA tables |
9207 | to PSA tables as shown below: |
9208 | |
9209 | SLA Table PSA Table |
9210 | ======== ======== |
9211 | xla_events_gt psa_xla_events_logs |
9212 | xla_validation_lines_gt psa_xla_validation_lines_logs |
9213 | xla_ae_lines_gt psa_xla_ae_lines_logs |
9214 | xla_ae_headers_gt psa_xla_ae_headers_logs |
9215 | |
9216 +===========================================================================================*/
9217
9218 PROCEDURE debug_xla_insert ( xla_events IN xla_events_table ,
9219 xla_validation_lines IN xla_validation_lines_table ,
9220 xla_ae_lines IN xla_ae_lines_table ,
9221 xla_ae_headers IN xla_ae_headers_table ,
9222 xla_distribution_links IN xla_distribution_links_table) IS
9223
9224 PRAGMA autonomous_transaction;
9225 i NUMBER;
9226
9227 BEGIN
9228
9229 FORALL i IN 1 .. xla_events.count
9230 INSERT INTO psa_xla_events_logs
9231 VALUES xla_events(i);
9232
9233 FORALL i IN 1 .. xla_validation_lines.count
9234 INSERT INTO psa_xla_validation_lines_logs
9235 VALUES xla_validation_lines(i);
9236
9237 FORALL i IN 1 .. xla_ae_lines.count
9238 INSERT INTO psa_xla_ae_lines_logs
9239 VALUES xla_ae_lines(i);
9240
9241 FORALL i IN 1 .. xla_ae_headers.count
9242 INSERT INTO psa_xla_ae_headers_logs
9243 VALUES xla_ae_headers(i);
9244
9245
9246 FORALL i IN 1 .. xla_distribution_links.count
9247 INSERT INTO psa_xla_dist_links_logs
9248 VALUES xla_distribution_links(i);
9249 COMMIT;
9250
9251 END debug_xla_insert ;
9252
9253
9254 /*===========================================================================================+
9255 | Function : DEBUG_XLA |
9256 | Description : This Procedure is used for SLA debugging purpose. |
9257 | It calls DEBUG_XLA_INSERT procedure to transfer data |
9258 | from global temporary SLA tables to PSA tables. |
9259 | |
9260 +===========================================================================================*/
9261
9262 PROCEDURE debug_xla (phase IN VARCHAR2) IS
9263
9264 l_xla_events xla_events_table;
9265 l_xla_validation_lines xla_validation_lines_table;
9266 l_xla_ae_lines xla_ae_lines_table;
9267 l_xla_ae_headers xla_ae_headers_table;
9268 l_xla_distribution_links xla_distribution_links_table;
9269
9270 BEGIN
9271
9272 IF g_xla_debug THEN
9273
9274 SELECT line_number,
9275 entity_id,
9276 application_id,
9277 ledger_id,
9278 entity_code,
9279 source_id_int_1,
9280 source_id_char_1,
9281 event_id,
9282 event_class_code,
9283 event_status_code,
9284 process_status_code,
9285 reference_num_1,
9286 reference_char_1,
9287 on_hold_flag,
9288 transaction_date,
9289 budgetary_control_flag,
9290 phase,
9291 sysdate
9292 BULK COLLECT INTO l_xla_events
9293 FROM xla_events_gt ;
9294
9295
9296 SELECT event_id,
9297 entity_id,
9298 ae_header_id,
9299 ae_line_num,
9300 accounting_date,
9301 balance_type_code,
9302 je_category_name,
9303 budget_version_id,
9304 ledger_id,
9305 entered_currency_code,
9306 entered_dr,
9307 entered_cr,
9308 accounted_dr,
9309 accounted_cr,
9310 code_combination_id,
9311 balancing_line_type,
9312 encumbrance_type_id,
9313 accounting_entry_status_code,
9314 period_name,
9315 phase,
9316 sysdate
9317 BULK COLLECT INTO l_xla_validation_lines
9318 FROM xla_validation_lines_gt ;
9319
9320
9321 SELECT ae_header_id,
9322 ae_line_num,
9323 source_distribution_id_char_1,
9324 source_distribution_id_char_2,
9325 source_distribution_id_char_3,
9326 source_distribution_id_char_4,
9327 source_distribution_id_char_5,
9328 source_distribution_id_num_1,
9329 source_distribution_id_num_2,
9330 source_distribution_id_num_3,
9331 source_distribution_id_num_4,
9332 source_distribution_id_num_5,
9333 source_distribution_type,
9334 bflow_application_id,
9335 bflow_entity_code,
9336 bflow_source_id_num_1,
9337 bflow_source_id_num_2,
9338 bflow_source_id_num_3,
9339 bflow_source_id_num_4,
9340 bflow_source_id_char_1,
9341 bflow_source_id_char_2,
9342 bflow_source_id_char_3,
9343 bflow_source_id_char_4,
9344 bflow_distribution_type,
9345 bflow_dist_id_num_1,
9346 bflow_dist_id_num_2,
9347 bflow_dist_id_num_3,
9348 bflow_dist_id_num_4,
9349 bflow_dist_id_num_5,
9350 bflow_dist_id_char_1,
9351 bflow_dist_id_char_2,
9352 bflow_dist_id_char_3,
9353 bflow_dist_id_char_4,
9354 bflow_dist_id_char_5,
9355 phase,
9356 sysdate
9357 BULK COLLECT INTO l_xla_ae_lines
9358 FROM xla_ae_lines_gt ;
9359
9360
9361 SELECT ae_header_id,
9362 ledger_id,
9363 event_id,
9364 event_type_code,
9365 accounting_entry_status_code ,
9366 balance_type_code,
9367 funds_status_code,
9368 phase,
9369 sysdate
9370 BULK COLLECT INTO l_xla_ae_headers
9371 FROM xla_ae_headers_gt ;
9372
9373 Select application_id ,
9374 event_id,
9375 ae_header_id,
9376 ae_line_num ,
9377 source_distribution_type ,
9378 source_distribution_id_char_1,
9379 source_distribution_id_char_2,
9380 source_distribution_id_char_3,
9381 source_distribution_id_char_4,
9382 source_distribution_id_char_5,
9383 source_distribution_id_num_1 ,
9384 source_distribution_id_num_2 ,
9385 source_distribution_id_num_3 ,
9386 source_distribution_id_num_4 ,
9387 source_distribution_id_num_5 ,
9388 tax_line_ref_id ,
9389 tax_summary_line_ref_id ,
9390 tax_rec_nrec_dist_ref_id ,
9391 statistical_amount,
9392 ref_ae_header_id ,
9393 ref_temp_line_num ,
9394 accounting_line_code,
9395 accounting_line_type_code,
9396 merge_duplicate_code ,
9397 temp_line_num ,
9398 ref_event_id ,
9399 line_definition_owner_code ,
9400 line_definition_code ,
9401 event_class_code ,
9402 event_type_code ,
9403 upg_batch_id ,
9404 calculate_acctd_amts_flag,
9405 calculate_g_l_amts_flag ,
9406 gain_or_loss_ref,
9407 rounding_class_code ,
9408 document_rounding_level,
9409 unrounded_entered_dr,
9410 unrounded_entered_cr ,
9411 doc_rounding_entered_amt,
9412 doc_rounding_acctd_amt,
9413 unrounded_accounted_cr ,
9414 unrounded_accounted_dr ,
9415 alloc_to_application_id,
9416 alloc_to_entity_code,
9417 alloc_to_source_id_num_1,
9418 alloc_to_source_id_num_2,
9419 alloc_to_source_id_num_3,
9420 alloc_to_source_id_num_4,
9421 alloc_to_source_id_char_1,
9422 alloc_to_source_id_char_2,
9423 alloc_to_source_id_char_3,
9424 alloc_to_source_id_char_4,
9425 alloc_to_distribution_type,
9426 alloc_to_dist_id_num_1,
9427 alloc_to_dist_id_num_2,
9428 alloc_to_dist_id_num_3,
9429 alloc_to_dist_id_num_4,
9430 alloc_to_dist_id_num_5,
9431 alloc_to_dist_id_char_1,
9432 alloc_to_dist_id_char_2,
9433 alloc_to_dist_id_char_3,
9434 alloc_to_dist_id_char_4,
9435 alloc_to_dist_id_char_5,
9436 applied_to_application_id,
9437 applied_to_entity_code ,
9438 applied_to_entity_id ,
9439 applied_to_source_id_num_1,
9440 applied_to_source_id_num_2,
9441 applied_to_source_id_num_3 ,
9442 applied_to_source_id_num_4 ,
9443 applied_to_source_id_char_1,
9444 applied_to_source_id_char_2,
9445 applied_to_source_id_char_3,
9446 applied_to_source_id_char_4,
9447 applied_to_distribution_type,
9448 applied_to_dist_id_num_1,
9449 applied_to_dist_id_num_2,
9450 applied_to_dist_id_num_3,
9451 applied_to_dist_id_num_4,
9452 applied_to_dist_id_num_5,
9453 applied_to_dist_id_char_1,
9454 applied_to_dist_id_char_2,
9455 applied_to_dist_id_char_3,
9456 applied_to_dist_id_char_4,
9457 applied_to_dist_id_char_5,
9458 phase,
9459 sysdate
9460 BULK COLLECT INTO l_xla_distribution_links
9461 FROM xla_distribution_links
9462 where event_id IN (SELECT event_id from psa_bc_xla_events_gt)
9463 and application_id = psa_bc_xla_pvt.g_application_id;
9464
9465
9466
9467 DEBUG_XLA_INSERT ( l_xla_events, l_xla_validation_lines, l_xla_ae_lines, l_xla_ae_headers , l_xla_distribution_links);
9468
9469 ELSE
9470 return;
9471
9472 END IF;
9473
9474 END debug_xla;
9475
9476
9477 /*===========================================================================================+
9478 | Function : BUDGETARY_CONTROL |
9479 | Description : BC API is invoked by SLA in package XLA_JE_VALIDATION_PKG.BUDGETARY_CONTROL |
9480 +===========================================================================================*/
9481
9482 FUNCTION budgetary_control (p_ledgerid IN NUMBER,
9483 p_return_code OUT NOCOPY VARCHAR2) return BOOLEAN IS
9484
9485 l_session_id gl_bc_packets.session_id%type;
9486 l_serial_id gl_bc_packets.serial_id%type;
9487
9488 l_packet_id gl_bc_packets.packet_id%type;
9489 l_bc_pkts bc_pkts_rec;
9490 l_packets num_rec;
9491 l_ret_code VARCHAR2(1);
9492 l_bc_ret_code VARCHAR2(1);
9493 l_s_status_cnt NUMBER(5);
9494 l_a_status_cnt NUMBER(5);
9495 l_f_status_cnt NUMBER(5);
9496 l_p_status_cnt NUMBER(5);
9497 l_t_status_cnt NUMBER(5);
9498 l_je_source_name xla_subledgers.je_source_name%type;
9499 invalid_je_source_name EXCEPTION;
9500 gl_bc_packets_empty EXCEPTION;
9501
9502 -- ========================= FND LOG ===========================
9503 l_full_path VARCHAR2(100);
9504 -- ========================= FND LOG ===========================
9505
9506 CURSOR get_je_source_name (p_application_id IN NUMBER) IS
9507 SELECT je_source_name
9508 FROM xla_subledgers
9509 WHERE application_id = p_application_id;
9510
9511 CURSOR get_status_per_header (p_packet_id IN NUMBER) IS
9512 SELECT ae_header_id,
9513 count(*) total_cnt,
9514 sum(decode(status_code, 'S', 1, 0)) success_cnt,
9515 sum(decode(status_code, 'A', 1, 0)) approved_cnt,
9516 sum(decode(status_code, 'F', 1, 0)) failed_cnt,
9517 sum(decode(status_code, 'R', 1, 0)) rejected_cnt
9518 FROM gl_bc_packets
9519 WHERE packet_id = p_packet_id
9520 GROUP BY ae_header_id;
9521
9522 CURSOR get_ledger_category (p_ledgerid IN NUMBER) IS
9523 SELECT ledger_category_code
9524 FROM gl_ledgers
9525 WHERE ledger_id = p_ledgerid;
9526
9527 CURSOR debug_xla_ae_headers_gt IS
9528 SELECT ae_header_id, ledger_id, entity_id, event_id,
9529 event_type_code, funds_status_code, accounting_entry_status_code,
9530 balance_type_code
9531 FROM xla_ae_headers_gt;
9532
9533 CURSOR debug_xla_ae_lines_gt IS
9534 SELECT event_id, ae_header_id, ae_line_num
9535 FROM xla_ae_lines_gt;
9536
9537 CURSOR debug_xla_val_lines_gt IS
9538 SELECT event_id, ae_header_id, ae_line_num, period_name,
9539 accounting_entry_status_code, balancing_line_type
9540 FROM xla_validation_lines_gt;
9541
9542 CURSOR debug_xla_events_gt IS
9543 SELECT application_id, event_id, event_date, event_type_code,
9544 reference_num_1
9545 FROM xla_events_gt;
9546
9547 CURSOR debug_xla_psa_bc_v IS
9548 SELECT event_id, ae_header_id, ae_line_num, entity_id, ledger_id,
9549 period_name
9550 FROM xla_psa_bc_lines_v;
9551
9552 CURSOR debug_psa_bc_alloc_gt IS
9553 SELECT hierarchy_id, ae_header_id, ae_line_num, event_id,
9554 status_code
9555 FROM psa_bc_alloc_gt;
9556
9557 -- Check whether all the events from XLA_EVENTS_GT have come to
9558 -- XLA_AE_LINES_GT.
9559 /* If any event is missed we will treat it as
9560 FATAL error because there was some setup problem in SLA. */
9561 CURSOR c_cnt_events IS
9562 SELECT (SELECT COUNT (*)
9563 FROM xla_events_gt) event_count,
9564 (SELECT COUNT (DISTINCT (event_id))
9565 FROM xla_ae_lines_gt) ae_event_count
9566 FROM DUAL;
9567
9568 -- check whether allocation attributes are used or not
9569 /* This is to avoid additional processing for allocation attributes
9570 if they are NOT used. */
9571 CURSOR c_chk_alloc_used is
9572 SELECT
9573 'Allocation attributes are used'
9574 FROM DUAL
9575 WHERE EXISTS
9576 (
9577 SELECT
9578 'Related transaction allocation setup exists'
9579 FROM psa_bc_alloc_v a,
9580 psa_bc_alloc_v b
9581 WHERE a.ROW_ID <> b.ROW_ID
9582 AND NVL (b.alloc_to_entity_code, 'X') = NVL (a.entity_code, 'X')
9583 AND NVL (b.alloc_to_source_id_num_1, -99) = NVL (a.source_id_int_1, -99)
9584 AND NVL (b.alloc_to_source_id_num_2, -99) = NVL (a.source_id_int_2, -99)
9585 AND NVL (b.alloc_to_source_id_num_3, -99) = NVL (a.source_id_int_3, -99)
9586 AND NVL (b.alloc_to_source_id_num_4, -99) = NVL (a.source_id_int_4, -99)
9587 AND NVL (b.alloc_to_source_id_char_1, 'X') = NVL (a.source_id_char_1, 'X')
9588 AND NVL (b.alloc_to_source_id_char_2, 'X') = NVL (a.source_id_char_2, 'X')
9589 AND NVL (b.alloc_to_source_id_char_3, 'X') = NVL (a.source_id_char_3, 'X')
9590 AND NVL (b.alloc_to_source_id_char_4, 'X') = NVL (a.source_id_char_4, 'X')
9591 AND NVL (b.alloc_to_application_id, -99) = NVL (a.application_id, -99)
9592 AND NVL (b.alloc_to_distribution_type, 'X') = NVL (a.source_distribution_type, 'X')
9593 AND NVL (b.alloc_to_dist_id_num_1, -99) = NVL (a.source_distribution_id_num_1, -99)
9594 AND NVL (b.alloc_to_dist_id_num_2, -99) = NVL (a.source_distribution_id_num_2, -99)
9595 AND NVL (b.alloc_to_dist_id_num_3, -99) = NVL (a.source_distribution_id_num_3, -99)
9596 AND NVL (b.alloc_to_dist_id_num_4, -99) = NVL (a.source_distribution_id_num_4, -99)
9597 AND NVL (b.alloc_to_dist_id_num_5, -99) = NVL (a.source_distribution_id_num_5, -99)
9598 AND NVL (b.alloc_to_dist_id_char_1, 'X') = NVL (a.source_distribution_id_char_1, 'X')
9599 AND NVL (b.alloc_to_dist_id_char_2, 'X') = NVL (a.source_distribution_id_char_2, 'X')
9600 AND NVL (b.alloc_to_dist_id_char_3, 'X') = NVL (a.source_distribution_id_char_3, 'X')
9601 AND NVL (b.alloc_to_dist_id_char_4, 'X') = NVL (a.source_distribution_id_char_4, 'X')
9602 AND NVL (b.alloc_to_dist_id_char_5, 'X') = NVL (a.source_distribution_id_char_5, 'X')
9603 )
9604 AND EXISTS
9605 (
9606 SELECT
9607 'Parent transaction allocation setup exists'
9608 FROM psa_bc_alloc_v a,
9609 psa_bc_alloc_v b
9610 WHERE a.ROW_ID = b.ROW_ID
9611 AND NVL (b.alloc_to_entity_code, 'X') = NVL (a.entity_code, 'X')
9612 AND NVL (b.alloc_to_source_id_num_1, -99) = NVL (a.source_id_int_1, -99)
9613 AND NVL (b.alloc_to_source_id_num_2, -99) = NVL (a.source_id_int_2, -99)
9614 AND NVL (b.alloc_to_source_id_num_3, -99) = NVL (a.source_id_int_3, -99)
9615 AND NVL (b.alloc_to_source_id_num_4, -99) = NVL (a.source_id_int_4, -99)
9616 AND NVL (b.alloc_to_source_id_char_1, 'X') = NVL (a.source_id_char_1, 'X')
9617 AND NVL (b.alloc_to_source_id_char_2, 'X') = NVL (a.source_id_char_2, 'X')
9618 AND NVL (b.alloc_to_source_id_char_3, 'X') = NVL (a.source_id_char_3, 'X')
9619 AND NVL (b.alloc_to_source_id_char_4, 'X') = NVL (a.source_id_char_4, 'X')
9620 AND NVL (b.alloc_to_application_id, -99) = NVL (a.application_id, -99)
9621 AND NVL (b.alloc_to_distribution_type, 'X') = NVL (a.source_distribution_type, 'X')
9622 AND NVL (b.alloc_to_dist_id_num_1, -99) = NVL (a.source_distribution_id_num_1, -99)
9623 AND NVL (b.alloc_to_dist_id_num_2, -99) = NVL (a.source_distribution_id_num_2, -99)
9624 AND NVL (b.alloc_to_dist_id_num_3, -99) = NVL (a.source_distribution_id_num_3, -99)
9625 AND NVL (b.alloc_to_dist_id_num_4, -99) = NVL (a.source_distribution_id_num_4, -99)
9626 AND NVL (b.alloc_to_dist_id_num_5, -99) = NVL (a.source_distribution_id_num_5, -99)
9627 AND NVL (b.alloc_to_dist_id_char_1, 'X') = NVL (a.source_distribution_id_char_1, 'X')
9628 AND NVL (b.alloc_to_dist_id_char_2, 'X') = NVL (a.source_distribution_id_char_2, 'X')
9629 AND NVL (b.alloc_to_dist_id_char_3, 'X') = NVL (a.source_distribution_id_char_3, 'X')
9630 AND NVL (b.alloc_to_dist_id_char_4, 'X') = NVL (a.source_distribution_id_char_4, 'X')
9631 AND NVL (b.alloc_to_dist_id_char_5, 'X') = NVL (a.source_distribution_id_char_5, 'X')
9632 )
9633 ;
9634
9635 -- Find out the base transactions
9636 /* Base transaction (e.g. PO) will be identified as their base
9637 transaction attributes will be same as allocation attributes */
9638 CURSOR c_get_parent_trx IS
9639 SELECT
9640 DISTINCT
9641 ENTITY_CODE ,
9642 SOURCE_ID_INT_1 ,
9643 SOURCE_ID_INT_2 ,
9644 SOURCE_ID_INT_3 ,
9645 SOURCE_ID_INT_4 ,
9646 SOURCE_ID_CHAR_1 ,
9647 SOURCE_ID_CHAR_2 ,
9648 SOURCE_ID_CHAR_3 ,
9649 SOURCE_ID_CHAR_4 ,
9650 APPLICATION_ID,
9651 SOURCE_DISTRIBUTION_ID_NUM_1 ,
9652 SOURCE_DISTRIBUTION_ID_NUM_2 ,
9653 SOURCE_DISTRIBUTION_ID_NUM_3 ,
9654 SOURCE_DISTRIBUTION_ID_NUM_4 ,
9655 SOURCE_DISTRIBUTION_ID_NUM_5 ,
9656 SOURCE_DISTRIBUTION_TYPE,
9657 SOURCE_DISTRIBUTION_ID_CHAR_1 ,
9658 SOURCE_DISTRIBUTION_ID_CHAR_2 ,
9659 SOURCE_DISTRIBUTION_ID_CHAR_3 ,
9660 SOURCE_DISTRIBUTION_ID_CHAR_4 ,
9661 SOURCE_DISTRIBUTION_ID_CHAR_5
9662 FROM psa_bc_alloc_v a
9663 WHERE EXISTS
9664 (
9665 SELECT
9666 'Accounting line is allocated to itself'
9667 FROM psa_bc_alloc_v b
9668 WHERE b.ROW_ID = a.ROW_ID
9669 AND NVL(b.ALLOC_TO_ENTITY_CODE, 'X') = NVL(a.ENTITY_CODE, 'X')
9670 AND NVL(b.ALLOC_TO_SOURCE_ID_NUM_1, -99)= NVL(a.SOURCE_ID_INT_1, -99)
9671 AND NVL(b.ALLOC_TO_SOURCE_ID_NUM_2, -99) = NVL(a.SOURCE_ID_INT_2, -99)
9672 AND NVL(b.ALLOC_TO_SOURCE_ID_NUM_3, -99) = NVL(a.SOURCE_ID_INT_3, -99)
9673 AND NVL(b.ALLOC_TO_SOURCE_ID_NUM_4, -99) = NVL(a.SOURCE_ID_INT_4, -99)
9674 AND NVL(b.ALLOC_TO_SOURCE_ID_CHAR_1, 'X') = NVL(a.SOURCE_ID_CHAR_1, 'X')
9675 AND NVL(b.ALLOC_TO_SOURCE_ID_CHAR_2, 'X') = NVL(a.SOURCE_ID_CHAR_2, 'X')
9676 AND NVL(b.ALLOC_TO_SOURCE_ID_CHAR_3, 'X') = NVL(a.SOURCE_ID_CHAR_3, 'X')
9677 AND NVL(b.ALLOC_TO_SOURCE_ID_CHAR_4, 'X') = NVL(a.SOURCE_ID_CHAR_4, 'X')
9678 AND NVL(b.alloc_to_application_id, -99) = NVL (a.application_id, -99)
9679 AND NVL(b.alloc_to_distribution_type, 'X') = NVL(a.source_distribution_type, 'X')
9680 AND NVL(b.alloc_to_dist_id_num_1, -99) = NVL(a.source_distribution_id_num_1, -99)
9681 AND NVL(b.alloc_to_dist_id_num_2, -99) = NVL(a.source_distribution_id_num_2, -99)
9682 AND NVL(b.alloc_to_dist_id_num_3, -99) = NVL(a.source_distribution_id_num_3, -99)
9683 AND NVL(b.alloc_to_dist_id_num_4, -99) = NVL(a.source_distribution_id_num_4, -99)
9684 AND NVL(b.alloc_to_dist_id_num_5, -99) = NVL(a.source_distribution_id_num_5, -99)
9685 AND NVL(b.alloc_to_dist_id_char_1, 'X') = NVL(a.source_distribution_id_char_1, 'X')
9686 AND NVL(b.alloc_to_dist_id_char_2, 'X') = NVL(a.source_distribution_id_char_2, 'X')
9687 AND NVL(b.alloc_to_dist_id_char_3, 'X') = NVL(a.source_distribution_id_char_3, 'X')
9688 AND NVL(b.alloc_to_dist_id_char_4, 'X') = NVL(a.source_distribution_id_char_4, 'X')
9689 AND NVL(b.alloc_to_dist_id_char_5, 'X') = NVL(a.source_distribution_id_char_5, 'X')
9690 )
9691 ;
9692
9693 -- For each base transactions find out its child transactions
9694 CURSOR c_get_child_trx (P_ENTITY_CODE VARCHAR2 ,
9695 P_SOURCE_ID_INT_1 NUMBER ,
9696 P_SOURCE_ID_INT_2 NUMBER,
9697 P_SOURCE_ID_INT_3 NUMBER,
9698 P_SOURCE_ID_INT_4 NUMBER,
9699 P_SOURCE_ID_CHAR_1 VARCHAR2,
9700 P_SOURCE_ID_CHAR_2 VARCHAR2,
9701 P_SOURCE_ID_CHAR_3 VARCHAR2,
9702 P_SOURCE_ID_CHAR_4 VARCHAR2,
9703 P_APPLICATION_ID VARCHAR2,
9704 P_SOURCE_DIST_ID_NUM_1 NUMBER,
9705 P_SOURCE_DIST_ID_NUM_2 NUMBER,
9706 P_SOURCE_DIST_ID_NUM_3 NUMBER,
9707 P_SOURCE_DIST_ID_NUM_4 NUMBER,
9708 P_SOURCE_DIST_ID_NUM_5 NUMBER,
9709 P_SOURCE_DIST_TYPE VARCHAR2,
9710 P_SOURCE_DIST_ID_CHAR_1 VARCHAR2,
9711 P_SOURCE_DIST_ID_CHAR_2 VARCHAR2,
9712 P_SOURCE_DIST_ID_CHAR_3 VARCHAR2,
9713 P_SOURCE_DIST_ID_CHAR_4 VARCHAR2,
9714 P_SOURCE_DIST_ID_CHAR_5 VARCHAR2)
9715 IS
9716 SELECT
9717 ae_header_id,
9718 ae_line_num,
9719 event_id
9720 FROM psa_bc_alloc_v
9721 WHERE NVL(ALLOC_TO_ENTITY_CODE, 'X') = NVL(p_entity_code, 'X')
9722 AND NVL(ALLOC_TO_SOURCE_ID_NUM_1, -99) = NVL(p_source_id_int_1, -99)
9723 AND NVL(ALLOC_TO_SOURCE_ID_NUM_2, -99) = NVL(p_source_id_int_2, -99)
9724 AND NVL(ALLOC_TO_SOURCE_ID_NUM_3, -99) = NVL(p_source_id_int_3, -99)
9725 AND NVL(ALLOC_TO_SOURCE_ID_NUM_4, -99) = NVL(p_source_id_int_4, -99)
9726 AND NVL(ALLOC_TO_SOURCE_ID_CHAR_1, 'X') = NVL(p_source_id_char_1, 'X')
9727 AND NVL(ALLOC_TO_SOURCE_ID_CHAR_2, 'X') = NVL(p_source_id_char_2, 'X')
9728 AND NVL(ALLOC_TO_SOURCE_ID_CHAR_3, 'X') = NVL(p_source_id_char_3, 'X')
9729 AND NVL(ALLOC_TO_SOURCE_ID_CHAR_4, 'X') = NVL(p_source_id_char_4, 'X')
9730 AND NVL(ALLOC_TO_APPLICATION_ID, -99) = NVL(p_application_id, -99)
9731 AND NVL(ALLOC_TO_DIST_ID_NUM_1 , -99) = NVL(p_source_dist_id_num_1 , -99)
9732 AND NVL(ALLOC_TO_DIST_ID_NUM_2 , -99) = NVL(p_source_dist_id_num_2 , -99)
9733 AND NVL(ALLOC_TO_DIST_ID_NUM_3 , -99) = NVL(p_source_dist_id_num_3 , -99)
9734 AND NVL(ALLOC_TO_DIST_ID_NUM_4 , -99) = NVL(p_source_dist_id_num_4 , -99)
9735 AND NVL(ALLOC_TO_DIST_ID_NUM_5 , -99) = NVL(p_source_dist_id_num_5 , -99)
9736 AND NVL(ALLOC_TO_DISTRIBUTION_TYPE, 'X') = NVL(p_source_dist_type, 'X')
9737 AND NVL(ALLOC_TO_DIST_ID_CHAR_1 , 'X') = NVL(p_source_dist_id_char_1 , 'X')
9738 AND NVL(ALLOC_TO_DIST_ID_CHAR_2 , 'X') = NVL(p_source_dist_id_char_2 , 'X')
9739 AND NVL(ALLOC_TO_DIST_ID_CHAR_3 , 'X') = NVL(p_source_dist_id_char_3 , 'X')
9740 AND NVL(ALLOC_TO_DIST_ID_CHAR_4 , 'X') = NVL(p_source_dist_id_char_4 , 'X')
9741 AND NVL(ALLOC_TO_DIST_ID_CHAR_5 , 'X') = NVL(p_source_dist_id_char_5 , 'X')
9742 ;
9743
9744 -- Get the hierarchy id
9745 CURSOR c_get_hierarchy_id
9746 IS
9747 SELECT
9748 DISTINCT(hierarchy_id)
9749 FROM psa_bc_alloc_gt;
9750
9751 -- Check whether for a hierarchy events funds check/reserve is
9752 -- failed/rejected.
9753 CURSOR c_chk_funds_hier(p_hierarchy_id NUMBER,
9754 p_session_id NUMBER,
9755 p_serial_id NUMBER)
9756 IS
9757 SELECT 'Funds Failure for hierarchy'
9758 FROM DUAL
9759 WHERE EXISTS
9760 (SELECT 'X' FROM GL_BC_PACKETS
9761 WHERE (ae_header_id, ae_line_num, event_id)
9762 IN (select ae_header_id, ae_line_num, event_id
9763 from psa_bc_alloc_gt
9764 where hierarchy_id = p_hierarchy_id
9765 and status_code = 'P'
9766 )
9767 AND status_code IN ('F', 'R')
9768 AND session_id = p_session_id
9769 AND serial_id = p_serial_id) ;
9770
9771 CURSOR c_pkt_retcode (p_packet_id NUMBER)
9772 IS
9773 SELECT DECODE (COUNT (*),
9774 COUNT (DECODE (SUBSTR (bp.result_code, 1, 1), 'P', 1)), DECODE
9775 (SIGN (COUNT (DECODE (bp.result_code,
9776 'P20', 1,
9777 'P22', 1,
9778 'P25', 1,
9779 'P27', 1,
9780 'P31', 1,
9781 'P35', 1,
9782 'P36', 1,
9783 'P37', 1,
9784 'P38', 1,
9785 'P39', 1
9786 )
9787 )
9788 ),
9789 0, 'S',
9790 1, 'A'
9791 ),
9792 COUNT (DECODE (SUBSTR (bp.result_code, 1, 1), 'F', 1)), 'F',
9793 DECODE (DECODE (psa_bc_xla_pvt.g_bc_mode,
9794 'C', 'Y',
9795 'M', 'N',
9796 'P', 'Y',
9797 'N'
9798 ),
9799 'Y', 'P',
9800 'F'
9801 )
9802 )
9803 FROM gl_bc_packets bp
9804 WHERE bp.packet_id = p_packet_id AND bp.template_id IS NULL;
9805
9806 -- Bug 5397349 .. Start
9807 CURSOR c_get_result_codes (p_packet_id IN NUMBER) IS
9808 SELECT result_code, ae_header_id, ae_line_num
9809 FROM gl_bc_packets
9810 WHERE packet_id = p_packet_id;
9811
9812 TYPE result_code_tbl_type IS TABLE OF gl_bc_packets.result_code%type INDEX BY binary_integer;
9813 TYPE xla_hdr_tbl_type IS TABLE OF gl_bc_packets.ae_header_id%type INDEX BY binary_integer;
9814 TYPE xla_line_tbl_type IS TABLE OF gl_bc_packets.ae_line_num%type INDEX BY binary_integer;
9815
9816 l_result_code_tbl result_code_tbl_type;
9817 l_xla_hdr_tbl xla_hdr_tbl_type;
9818 l_xla_line_tbl xla_line_tbl_type;
9819 -- Bug 5397349 .. End
9820
9821 l_var_1 number;
9822 l_var_2 number;
9823 l_xla_hdr_status VARCHAR2(1);
9824 l_ae_lines_gt ae_lines_gt_rec;
9825 l_validation_lines_gt validation_lines_gt_rec;
9826 l_ledger_category gl_ledgers.ledger_category_code%type;
9827 l_event_cnt NUMBER;
9828 l_ae_event_cnt NUMBER;
9829
9830 -- Allocation Attributes related variables
9831 l_parent_trx c_get_parent_trx%ROWTYPE;
9832 l_child_trx c_get_child_trx%ROWTYPE;
9833 dummy VARCHAR2(100);
9834 l_alloc_used VARCHAR2(1);
9835 l_alloc_event_cnt NUMBER;
9836 l_xla_event_cnt NUMBER;
9837 l_parent_cnt NUMBER;
9838
9839 BEGIN
9840
9841 l_full_path := g_path || 'budgetary_control';
9842
9843 -- ====== FND LOG ======
9844 psa_utils.debug_other_string(g_state_level,l_full_path,
9845 ' BCTRL -> P_LEDGERID = '||p_ledgerid);
9846 psa_utils.debug_other_string(g_state_level,l_full_path,
9847 ' BCTRL -> MODE = '||PSA_BC_XLA_PVT.G_BC_MODE);
9848 psa_utils.debug_other_string(g_state_level,l_full_path,
9849 ' BCTRL -> OVERRIDE = '||PSA_BC_XLA_PVT.G_OVERRIDE_FLAG);
9850 psa_utils.debug_other_string(g_state_level,l_full_path,
9851 ' BCTRL -> USER_ID = '||PSA_BC_XLA_PVT.G_USER_ID);
9852 psa_utils.debug_other_string(g_state_level,l_full_path,
9853 ' BCTRL -> RESP_ID = '||PSA_BC_XLA_PVT.G_USER_RESP_ID);
9854 -- ====== FND LOG ======
9855
9856 -- First invoke GLXFIN and assign values to global variables.
9857
9858 -- ====== FND LOG ======
9859 psa_utils.debug_other_string(g_state_level,l_full_path, ' BCTRL -> Invoking glxfin() ');
9860 -- ====== FND LOG ======
9861
9862 if not glxfin (p_ledgerid => p_ledgerid,
9863 p_packetid => 0,
9864 p_mode => PSA_BC_XLA_PVT.G_BC_MODE,
9865 p_override => PSA_BC_XLA_PVT.G_OVERRIDE_FLAG,
9866 p_conc_flag => 'N',
9867 p_user_id => PSA_BC_XLA_PVT.G_USER_ID,
9868 p_user_resp_id => PSA_BC_XLA_PVT.G_USER_RESP_ID,
9869 p_calling_prog_flag => 'S') then
9870
9871 -- ====== FND LOG ======
9872 psa_utils.debug_other_string(g_error_level,l_full_path, ' BCTRL -> glxfin failed ');
9873 psa_utils.debug_other_string(g_error_level,l_full_path, ' BCTRL -> ERROR: FATAL ');
9874 -- ====== FND LOG ======
9875
9876 p_return_code := 'T';
9877 return FALSE;
9878 end if;
9879
9880 -- Invoke the DEBUG_XLA procedure to transfer data from XLA global temporary tables to
9881 -- PSA regular tables.
9882
9883 debug_xla ( 'BUDGETARY_CONTROL_START' );
9884
9885 -- Check whether all the events in XLA_EVENTS_GT
9886 -- are available in XLA_AE_LINES_GT.
9887 /* If some events are missing that means that there is some issue in SLA
9888 setup for the event, that's why SLA didn't put that event to be
9889 considered for accounting. In this case Funds Checker API
9890 will treat this as an FATAL situation and will not process further. */
9891 OPEN c_cnt_events;
9892 FETCH c_cnt_events INTO l_event_cnt, l_ae_event_cnt;
9893 CLOSE c_cnt_events;
9894
9895 -- ====== FND LOG ======
9896 psa_utils.debug_other_string(g_error_level,l_full_path,
9897 ' BCTRL -> Count of events in XLA_EVENTS_GT: '||l_event_cnt);
9898 psa_utils.debug_other_string(g_error_level,l_full_path,
9899 ' BCTRL -> Count of events in XLA_AE_LINES_GT: '||l_ae_event_cnt);
9900 -- ====== FND LOG ======
9901
9902 fnd_file.put_line(fnd_file.log,'The following are the invalid accounting errrors');
9903 fnd_file.put_line(fnd_file.log,'=============================================== ');
9904 for acc_error in ( select document_reference , encoded_message
9905 from psa_bc_accounting_errors b
9906 where event_id in (select event_id from xla_events_gt))
9907 loop
9908 fnd_file.put_line(fnd_file.log , ' document_referece ' || acc_error.document_reference);
9909 fnd_file.put_line(fnd_file.log , acc_error.encoded_message);
9910 End loop;
9911
9912 IF NOT(NVL(l_ae_event_cnt, 0) = l_event_cnt) THEN
9913 -- ====== FND LOG ======
9914 psa_utils.debug_other_string(g_error_level,l_full_path, ' BCTRL -> Budgetary_Control failed ');
9915 psa_utils.debug_other_string(g_error_level,l_full_path, ' BCTRL -> ERROR: FATAL ');
9916 psa_utils.debug_other_string(g_error_level,l_full_path, ' BCTRL p_return_code -> T');
9917 psa_utils.debug_other_string(g_error_level,l_full_path, ' BCTRL Return False ');
9918
9919 fnd_file.put_line(fnd_file.log,'The following entities have not been processed');
9920 fnd_file.put_line(fnd_file.log,'======================================= ');
9921 for missing_entity in
9922 ( select e.entity_id,g.event_id,g.source_id_int_2,e.transaction_number
9923 from xla_transaction_entities_upg e , xla_events_gt g
9924 where g.entity_id = e.entity_id
9925 and g.event_id not in (select event_id from xla_ae_lines_gt) )
9926 loop
9927 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 );
9928 end loop;
9929
9930
9931 -- ====== FND LOG ======
9932
9933 p_return_code := 'T';
9934 return FALSE;
9935 END IF;
9936
9937 -- Initialize the collection variables
9938
9939 -- ====== FND LOG ======
9940 psa_utils.debug_other_string(g_state_level,l_full_path, ' BCTRL -> Initializing collection ');
9941 -- ====== FND LOG ======
9942
9943 l_packets := num_rec();
9944
9945 -- Get the session_id and serial# for the current session
9946 -- These columns will then be inserted in gl_bc_packets.
9947
9948 -- ====== FND LOG ======
9949 psa_utils.debug_other_string(g_state_level,l_full_path, ' BCTRL -> Invoking get_session_details() ');
9950 -- ====== FND LOG ======
9951
9952 get_session_details(l_session_id, l_serial_id);
9953
9954 -- ====== FND LOG ======
9955 psa_utils.debug_other_string(g_state_level,l_full_path, ' BCTRL -> Session_Id = '||l_session_id);
9956 psa_utils.debug_other_string(g_state_level,l_full_path, ' BCTRL -> Serial_Id = '||l_serial_id);
9957 -- ====== FND LOG ======
9958
9959 -- Get the JE_SOURCE_NAME for current application
9960
9961 -- ====== FND LOG ======
9962 psa_utils.debug_other_string(g_state_level,l_full_path, ' BCTRL -> Get Je_Source_name ');
9963 -- ====== FND LOG ======
9964
9965 open get_je_source_name(PSA_BC_XLA_PVT.G_APPLICATION_ID);
9966 fetch get_je_source_name into l_je_source_name;
9967 if get_je_source_name%notfound then
9968 raise invalid_je_source_name;
9969 end if;
9970 close get_je_source_name;
9971
9972
9973 -- ====== FND LOG ======
9974 psa_utils.debug_other_string(g_state_level,l_full_path, ' BCTRL -> JE_SOURCE_NAME = '||l_je_source_name);
9975 -- ====== FND LOG ======
9976
9977 --================== Allocation Attributes first level of validation Logic Start ======================
9978 /* First level of validation for allocation attributes is two fold:
9979 1) We check whether transaction lines are related with allocation attributes or not.
9980 If allocation attributes are NOT used we do the normal processing.
9981 2) Using allocation attributes we find out the relationship amongst trx lines and
9982 store this information into PSA_BC_ALLOC_GT. Events stored in this table are sampled with
9983 events of XLA_PSA_BC_LINES_V. If any event is missing we disallow the group of related
9984 transaction rows to go in for funds operation. */
9985
9986 -- Preliminary check for allocation attributes usage.
9987 OPEN c_chk_alloc_used;
9988 FETCH c_chk_alloc_used INTO dummy;
9989
9990 IF c_chk_alloc_used%FOUND THEN
9991 CLOSE c_chk_alloc_used;
9992 l_alloc_used := 'Y';
9993 ELSE
9994 CLOSE c_chk_alloc_used;
9995 l_alloc_used := 'N';
9996 END IF;
9997
9998 -- ====== FND LOG ======
9999 psa_utils.debug_other_string(g_state_level,l_full_path,
10000 ' BCTRL -> Allocation Attributes used (Y/N) = '||l_alloc_used);
10001 -- ====== FND LOG ======
10002
10003 IF (l_alloc_used = 'Y') THEN
10004 -- Initialize Parent counter;
10005 l_parent_cnt := 1;
10006 -- Find parent transactions;
10007 OPEN c_get_parent_trx;
10008 LOOP
10009 FETCH c_get_parent_trx INTO l_parent_trx;
10010 EXIT WHEN c_get_parent_trx%NOTFOUND;
10011 -- Find child transactions
10012 OPEN c_get_child_trx(l_parent_trx.ENTITY_CODE ,
10013 l_parent_trx.SOURCE_ID_INT_1 ,
10014 l_parent_trx.SOURCE_ID_INT_2 ,
10015 l_parent_trx.SOURCE_ID_INT_3 ,
10016 l_parent_trx.SOURCE_ID_INT_4 ,
10017 l_parent_trx.SOURCE_ID_CHAR_1 ,
10018 l_parent_trx.SOURCE_ID_CHAR_2 ,
10019 l_parent_trx.SOURCE_ID_CHAR_3 ,
10020 l_parent_trx.SOURCE_ID_CHAR_4 ,
10021 l_parent_trx.APPLICATION_ID,
10022 l_parent_trx.SOURCE_DISTRIBUTION_ID_NUM_1 ,
10023 l_parent_trx.SOURCE_DISTRIBUTION_ID_NUM_2 ,
10024 l_parent_trx.SOURCE_DISTRIBUTION_ID_NUM_3 ,
10025 l_parent_trx.SOURCE_DISTRIBUTION_ID_NUM_4 ,
10026 l_parent_trx.SOURCE_DISTRIBUTION_ID_NUM_5 ,
10027 l_parent_trx.SOURCE_DISTRIBUTION_TYPE,
10028 l_parent_trx.SOURCE_DISTRIBUTION_ID_CHAR_1 ,
10029 l_parent_trx.SOURCE_DISTRIBUTION_ID_CHAR_2 ,
10030 l_parent_trx.SOURCE_DISTRIBUTION_ID_CHAR_3 ,
10031 l_parent_trx.SOURCE_DISTRIBUTION_ID_CHAR_4 ,
10032 l_parent_trx.SOURCE_DISTRIBUTION_ID_CHAR_5
10033 );
10034 LOOP
10035 FETCH c_get_child_trx INTO l_child_trx;
10036 EXIT WHEN c_get_child_trx%NOTFOUND;
10037 -- now insert parent and child transactions in psa_bc_alloc_gt
10038 -- with a initial status of 'U' (Unprocessed)
10039 INSERT INTO psa_bc_alloc_gt (
10040 hierarchy_id,
10041 ae_header_id,
10042 ae_line_num,
10043 event_id,
10044 status_code
10045 ) VALUES (
10046 l_parent_cnt,
10047 l_child_trx.ae_header_id,
10048 l_child_trx.ae_line_num,
10049 l_child_trx.event_id,
10050 'U'
10051 );
10052 END LOOP;
10053 CLOSE c_get_child_trx;
10054 -- Increase the parent counter;
10055 l_parent_cnt := l_parent_cnt + 1;
10056 END LOOP;
10057 CLOSE c_get_parent_trx;
10058
10059 -- Now we will check that which hierarchy events should be
10060 -- allowed to go in funds checker by setting their
10061 -- status_code to 'P'(Passed) or 'F'(Failed)
10062 FOR h IN c_get_hierarchy_id
10063 LOOP
10064 SELECT
10065 COUNT(DISTINCT(event_id))
10066 INTO l_alloc_event_cnt
10067 FROM psa_bc_alloc_gt
10068 WHERE hierarchy_id = h.hierarchy_id;
10069
10070 -- ======================== FND LOG =============================
10071 psa_utils.debug_other_string(g_state_level, l_full_path, ' l_alloc_event_cnt -> '||l_alloc_event_cnt);
10072 -- ======================== FND LOG =============================
10073
10074 SELECT
10075 COUNT(DISTINCT(xv.event_id))
10076 INTO l_xla_event_cnt
10077 FROM xla_psa_bc_lines_v xv
10078 WHERE xv.event_id IN
10079 (
10080 (
10081 SELECT
10082 pa1.event_id
10083 FROM psa_bc_alloc_gt pa1
10084 WHERE pa1.hierarchy_id = h.hierarchy_id
10085 )
10086 MINUS
10087 (
10088 SELECT
10089 pa2.event_id
10090 FROM psa_bc_alloc_gt pa2
10091 WHERE pa2.event_id = xv.event_id
10092 AND pa2.status_code = 'F'
10093 )
10094 );
10095
10096 -- ======================== FND LOG =============================
10097 psa_utils.debug_other_string(g_state_level, l_full_path, ' l_xla_event_cnt -> '||l_xla_event_cnt);
10098 -- ======================== FND LOG =============================
10099
10100 -- Compare both the counts. if they are equal
10101 -- then the hierarchy events are eligible for funds check
10102 IF (l_alloc_event_cnt = NVL(l_xla_event_cnt, 0)) THEN
10103 UPDATE
10104 psa_bc_alloc_gt
10105 SET status_code = 'P'
10106 WHERE hierarchy_id = h.hierarchy_id;
10107 -- ====== FND LOG ======
10108 psa_utils.debug_other_string(g_state_level, l_full_path, ' BCTRL -> Updated '||sql%rowcount||
10109 ' rows.');
10110 -- ====== FND LOG ======
10111 ELSE
10112 UPDATE
10113 psa_bc_alloc_gt
10114 SET status_code = 'F'
10115 WHERE hierarchy_id = h.hierarchy_id;
10116 -- ====== FND LOG ======
10117 psa_utils.debug_other_string(g_state_level, l_full_path, ' BCTRL -> Updated '||sql%rowcount||
10118 ' rows.');
10119 -- ====== FND LOG ======
10120 END IF;
10121 END LOOP;
10122 END IF;
10123 --=================== Allocation Attributes first level of validation Logic End ===========================
10124
10125
10126 -- Now select the event_id and other information to be inserted
10127 -- in gl_bc_packets in plsql table. We will select all event_id
10128 -- to be inserted at one go for performance reasons. I have selected all columns
10129 -- from gl_bc_packets and put NULL for columns which should not be populated. This is to
10130 -- overcome a limitation with FORALL clause later in the code.
10131
10132
10133 -- ====== FND LOG ======
10134 psa_utils.debug_other_string(g_state_level,l_full_path, ' BCTRL -> Populate l_bc_pkts pl/sql table ');
10135 -- ====== FND LOG ======
10136
10137 SELECT NULL, -- Packet_id is initially NULL. Populated later in the code
10138 p_ledgerid, -- Since XLA view does not provide this column, use parameter
10139 nvl(l_je_source_name, 'Manual'),
10140 xv.je_category_name,
10141 xv.code_combination_id,
10142 xv.balance_type_code,
10143 xv.period_name,
10144 ps.period_year,
10145 ps.period_num,
10146 ps.quarter_num,
10147 xv.entered_currency_code,
10148 -- decode(psa_bc_xla_pvt.g_bc_mode, 'C', 'C', 'P'), Bug 6452856.
10149 decode(psa_bc_xla_pvt.g_bc_mode, 'C', 'C','M', 'C', 'P'),
10150 sysdate,
10151 g_user_id,
10152 xv.budget_version_id, -- BUDGET_VERSION_ID
10153 xv.encumbrance_type_id,
10154 NULL, -- TEMPLATE_ID
10155 xv.entered_dr,
10156 xv.entered_cr,
10157 xv.accounted_dr,
10158 xv.accounted_cr,
10159 NULL, -- USSGL_TRANSACTION_CODE
10160 NULL, -- ORIGINATING_ROWID
10161 NULL, -- ACCOUNT_SEGMENT_VALUE
10162 NULL, -- AUTOMATIC_ENCUMBRANCE_FLAG
10163 NULL, -- FUNDING_BUDGET_VERSION_ID
10164 NULL, -- FUNDS_CHECK_LEVEL_CODE
10165 NULL, -- AMOUNT_TYPE
10166 NULL, -- BOUNDARY_CODE
10167 NULL, -- TOLERANCE_PERCENTAGE
10168 NULL, -- TOLERANCE_AMOUNT
10169 NULL, -- OVERRIDE_AMOUNT
10170 NULL, -- DR_CR_CODE
10171 NULL, -- ACCOUNT_TYPE
10172 NULL, -- ACCOUNT_CATEGORY_CODE
10173 NULL, -- EFFECT_ON_FUNDS_CODE
10174 NULL, -- RESULT_CODE
10175 NULL, -- BUDGET_POSTED_BALANCE
10176 NULL, -- ACTUAL_POSTED_BALANCE
10177 NULL, -- ENCUMBRANCE_POSTED_BALANCE
10178 NULL, -- BUDGET_APPROVED_BALANCE
10179 NULL, -- ACTUAL_APPROVED_BALANCE
10180 NULL, -- ENCUMBRANCE_APPROVED_BALANCE
10181 NULL, -- BUDGET_PENDING_BALANCE
10182 NULL, -- ACTUAL_PENDING_BALANCE
10183 NULL, -- ENCUMBRANCE_PENDING_BALANCE
10184 NULL, -- REFERENCE1
10185 NULL, -- REFERENCE2
10186 NULL, -- REFERENCE3
10187 NULL, -- REFERENCE4
10188 NULL, -- REFERENCE5
10189 NULL, -- JE_BATCH_NAME
10190 -1, -- JE_BATCH_ID
10191 NULL, -- JE_HEADER_ID
10192 NULL, -- JE_LINE_NUM
10193 NULL, -- JE_LINE_DESCRIPTION
10194 NULL, -- REFERENCE6
10195 NULL, -- REFERENCE7
10196 NULL, -- REFERENCE8
10197 NULL, -- REFERENCE9
10198 NULL, -- REFERENCE10
10199 NULL, -- REFERENCE11
10200 NULL, -- REFERENCE12
10201 NULL, -- REFERENCE13
10202 NULL, -- REFERENCE14
10203 NULL, -- REFERENCE15
10204 NULL, -- REQUEST_ID
10205 NULL, -- USSGL_PARENT_ID
10206 NULL, -- USSGL_LINK_TO_PARENT_ID
10207 xv.event_id,
10208 xv.ae_header_id,
10209 xv.ae_line_num,
10210 NULL, -- BC_DATE
10211 xv.source_distribution_type,
10212 xv.source_distribution_id_char_1,
10213 xv.source_distribution_id_char_2,
10214 xv.source_distribution_id_char_3,
10215 xv.source_distribution_id_char_4,
10216 xv.source_distribution_id_char_5,
10217 xv.source_distribution_id_num_1,
10218 xv.source_distribution_id_num_2,
10219 xv.source_distribution_id_num_3,
10220 xv.source_distribution_id_num_4,
10221 xv.source_distribution_id_num_5,
10222 l_session_id,
10223 l_serial_id,
10224 psa_bc_xla_pvt.g_application_id,
10225 xv.entity_id,
10226 NULL -- GROUP_ID
10227 BULK COLLECT INTO l_bc_pkts
10228 FROM xla_psa_bc_lines_v xv,
10229 gl_period_statuses ps
10230 WHERE ps.ledger_id = p_ledgerid and
10231 xv.period_name = ps.period_name and
10232 ps.application_id = 101 and
10233 -- Bug 4778812 start
10234 (
10235 (l_alloc_used = 'Y' and
10236 xv.event_id IN (
10237 SELECT event_id
10238 FROM psa_bc_alloc_gt
10239 WHERE status_code = 'P')
10240 )
10241 OR
10242 (l_alloc_used = 'N')
10243 )
10244 -- Bug 4778812 end
10245 ORDER BY xv.entity_id, (nvl(entered_dr, 0)-nvl(entered_cr, 0)), source_distribution_id_num_1;
10246
10247 IF SQL%NOTFOUND THEN
10248
10249 OPEN get_ledger_category(p_ledgerid);
10250 FETCH get_ledger_category INTO l_ledger_category;
10251 CLOSE get_ledger_category;
10252
10253 -- ====== FND LOG ======
10254 psa_utils.debug_other_string(g_state_level,l_full_path, ' BCTRL -> Ledger Category: '||l_ledger_category);
10255 psa_utils.debug_other_string(g_state_level,l_full_path, ' BCTRL -> Application Id: '||psa_bc_xla_pvt.g_application_id);
10256 -- ====== FND LOG ======
10257
10258 IF (l_ledger_category = 'PRIMARY') OR (psa_bc_xla_pvt.g_application_id = 602) THEN
10259 -- ==================== FND LOG ===========================
10260 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');
10261 -- ==================== FND LOG ===========================
10262
10263 raise gl_bc_packets_empty;
10264 ELSE
10265
10266 -- ====== FND LOG ======
10267 psa_utils.debug_other_string(g_state_level,l_full_path, ' BCTRL -> Do not process for Secondary Ledger ');
10268 psa_utils.debug_other_string(g_state_level,l_full_path, ' BCTRL -> Return True');
10269 psa_utils.debug_other_string(g_state_level,l_full_path, ' BCTRL p_return_code -> S ');
10270 -- ====== FND LOG ======
10271 p_return_code := 'S';
10272 return true;
10273 END IF;
10274
10275 ELSE
10276
10277 -- ====== FND LOG ======
10278 psa_utils.debug_other_string(g_state_level,l_full_path, ' BCTRL -> Populated '||sql%rowcount||' rows. ');
10279 -- ====== FND LOG ======
10280 END IF;
10281
10282 -- Note above that the packet_id column was assigned a NULL value.
10283 -- Since packet_id will be unique per entity_id, we will use the
10284 -- following plsql logic to assign packet_id for each row above.
10285 -- Logic: Check if this is the first packet_id to be processed.
10286 -- If First_Packet_id then => assign new packet_id
10287 -- Elsif (Current Entity Id <> Previous Entity Id) then => assign new packet_id
10288 -- Else assign earlier packet_id.
10289
10290 FOR x in 1..l_bc_pkts.count
10291 LOOP
10292
10293 if (x = 1) then
10294 l_packet_id := get_packet_id;
10295 l_packets.extend(1);
10296 l_packets(l_packets.count) := l_packet_id;
10297 elsif (l_bc_pkts(x).entity_id <> l_bc_pkts(x-1).entity_id) then
10298 l_packet_id := get_packet_id;
10299 l_packets.extend(1);
10300 l_packets(l_packets.count) := l_packet_id;
10301 end if;
10302
10303 l_bc_pkts(x).packet_id := l_packet_id;
10304
10305 -- ====== FND LOG ======
10306 psa_utils.debug_other_string(g_state_level,l_full_path, ' BCTRL -> Row '||x||' assigned packet_id '||l_packet_id);
10307 -- ====== FND LOG ======
10308
10309 END LOOP;
10310
10311 -- Insert autonomous procedure populate_bc_pkts to insert data in gl_bc_packets
10312
10313 -- ====== FND LOG ======
10314 psa_utils.debug_other_string(g_state_level,l_full_path, ' BCTRL -> Invoking populate_bc_pkts() ');
10315 -- ====== FND LOG ======
10316
10317 IF NOT populate_bc_pkts (l_bc_pkts) THEN
10318 -- ====== FND LOG ======
10319 psa_utils.debug_other_string(g_error_level,l_full_path, ' BCTRL -> populate_bc_pkts() failed. ');
10320 psa_utils.debug_other_string(g_error_level,l_full_path, ' BCTRL -> ERROR: FATAL. ');
10321 psa_utils.debug_other_string(g_error_level,l_full_path, ' BCTRL -> p_return_code -> T');
10322 psa_utils.debug_other_string(g_error_level,l_full_path, ' BCTRL -> Return false ');
10323 -- ====== FND LOG ======
10324 p_return_code := 'T';
10325 return FALSE;
10326 END IF;
10327
10328 -- Invoke funds checker per packet_id. Update the relevant SLA tables.
10329
10330 -- ====== FND LOG ======
10331 psa_utils.debug_other_string(g_state_level,l_full_path, ' BCTRL -> Invoking glxfck() per packet.');
10332 -- ====== FND LOG ======
10333
10334 FOR i IN 1..l_packets.count
10335 LOOP
10336
10337 -- ====== FND LOG ======
10338 psa_utils.debug_other_string(g_state_level,l_full_path,
10339 ' BCTRL -> Invoking glxfck() for packet_id '||l_packets(i));
10340 -- ====== FND LOG ======
10341
10342 IF NOT glxfck( p_ledgerid ,
10343 l_packets(i) ,
10344 PSA_BC_XLA_PVT.G_BC_MODE ,
10345 PSA_BC_XLA_PVT.G_OVERRIDE_FLAG ,
10346 'N' ,
10347 PSA_BC_XLA_PVT.G_USER_ID ,
10348 PSA_BC_XLA_PVT.G_USER_RESP_ID ,
10349 'S' ,
10350 l_ret_code ) THEN
10351
10352 -- ====== FND LOG ======
10353 psa_utils.debug_other_string(g_state_level,l_full_path, ' BCTRL -> glxfck() failed ');
10354 -- ====== FND LOG ======
10355
10356 -- ============================== FND LOG =========================
10357 psa_utils.debug_other_string(g_state_level,l_full_path, ' BCTRL l_ret_code -> T ');
10358 -- ============================== FND LOG =========================
10359
10360 l_ret_code := 'T';
10361 END IF;
10362
10363 -- Update Funds_Status_Code column in XLA_AE_HEADERS_GT
10364
10365 -- ====== FND LOG ======
10366 psa_utils.debug_other_string(g_state_level, l_full_path, ' BCTRL -> Update funds_status_code '||
10367 'of xla_ae_headers_gt ');
10368 -- ====== FND LOG ======
10369
10370 IF (PSA_BC_XLA_PVT.G_BC_MODE = 'P') AND (l_ret_code <> 'T') THEN
10371 FOR y IN get_status_per_header(l_packets(i))
10372 LOOP
10373 -- ====== FND LOG ======
10374 psa_utils.debug_other_string(g_state_level,l_full_path, ' BCTRL -> GET_STATUS_PER_HEADER DETAILS ');
10375 psa_utils.debug_other_string(g_state_level,l_full_path, ' BCTRL -> ----------------------------- ');
10376 psa_utils.debug_other_string(g_state_level,l_full_path, ' BCTRL -> Y.AE_HEADER_ID = '||y.ae_header_id);
10377 psa_utils.debug_other_string(g_state_level,l_full_path, ' BCTRL -> Y.SUCCESS_CNT = '||y.success_cnt);
10378 psa_utils.debug_other_string(g_state_level,l_full_path, ' BCTRL -> Y.APPROVED_CNT = '||y.approved_cnt);
10379 psa_utils.debug_other_string(g_state_level,l_full_path, ' BCTRL -> Y.FAILED_CNT = '||y.failed_cnt);
10380 psa_utils.debug_other_string(g_state_level,l_full_path, ' BCTRL -> Y.REJECTED_CNT = '||y.rejected_cnt);
10381 psa_utils.debug_other_string(g_state_level,l_full_path, ' BCTRL -> Y.TOTAL_CNT = '||y.total_cnt);
10382 -- ====== FND LOG ======
10383
10384 IF (y.success_cnt = y.total_cnt) OR (y.approved_cnt = y.total_cnt) THEN
10385 SELECT nvl(min('A'), 'S') into l_xla_hdr_status
10386 FROM gl_bc_packets
10387 WHERE packet_id = l_packets(i) and
10388 ae_header_id = y.ae_header_id and
10389 result_code IN ('P20', 'P22', 'P25', 'P27', 'P31', 'P35', 'P36', 'P37',
10390 'P38', 'P39');
10391 ELSIF (y.failed_cnt = y.total_cnt) OR (y.rejected_cnt = y.total_cnt) THEN
10392 l_xla_hdr_status := 'F';
10393 ELSE
10394 l_xla_hdr_status := 'P';
10395 END IF;
10396
10397 -- ============================== FND LOG =========================
10398 psa_utils.debug_other_string(g_state_level,l_full_path, ' BCTRL l_xla_hdr_status -> '||l_xla_hdr_status);
10399 -- ============================== FND LOG =========================
10400
10401 UPDATE xla_ae_headers_gt
10402 SET funds_status_code = l_xla_hdr_status
10403 WHERE ae_header_id = y.ae_header_id and
10404 ledger_id = p_ledgerid;
10405
10406 IF SQL%FOUND THEN
10407 -- ====== FND LOG ======
10408 psa_utils.debug_other_string(g_state_level, l_full_path, ' BCTRL -> XLA Header '||y.ae_header_id||
10409 ', Status updated to '||l_xla_hdr_status);
10410 -- ====== FND LOG ======
10411 END IF;
10412
10413 END LOOP;
10414 ELSE
10415 UPDATE xla_ae_headers_gt
10416 SET funds_status_code = l_ret_code
10417 WHERE ae_header_id IN (SELECT ae_header_id
10418 FROM gl_bc_packets
10419 WHERE packet_id = l_packets(i)) and
10420 ledger_id = p_ledgerid;
10421
10422 -- ====== FND LOG ======
10423 psa_utils.debug_other_string(g_state_level, l_full_path, ' BCTRL -> Updated funds_status_code of '||
10424 sql%rowcount||' rows successfully. ');
10425 -- ====== FND LOG ======
10426 END IF;
10427
10428 -- Update the l_*_status_cnt variables.
10429
10430 IF (l_ret_code IN ('S','A')) THEN
10431 l_s_status_cnt := nvl(l_s_status_cnt, 0) + 1;
10432 ELSIF (l_ret_code = 'F') THEN
10433 l_f_status_cnt := nvl(l_f_status_cnt, 0) + 1;
10434 ELSIF (l_ret_code = 'P') THEN
10435 l_p_status_cnt := nvl(l_p_status_cnt, 0) + 1;
10436 ELSIF (l_ret_code = 'T') OR (l_ret_code IS NULL) THEN
10437 l_t_status_cnt := nvl(l_t_status_cnt, 0) + 1;
10438 END IF;
10439
10440 END LOOP;
10441
10442 -- Update Funds_Status_Code column in XLA_VALIDATION_LINES_GT
10443
10444 -- ====== FND LOG ======
10445 psa_utils.debug_other_string(g_state_level, l_full_path, ' BCTRL -> Update funds_status_code '||
10446 'of xla_validation_lines_gt');
10447 -- ====== FND LOG ======
10448
10449 -- Bug 5397349 .. Start
10450
10451 FOR i IN 1..l_packets.count
10452 LOOP
10453
10454 OPEN c_get_result_codes (l_packets(i));
10455
10456 LOOP
10457 FETCH c_get_result_codes bulk collect into l_result_code_tbl, l_xla_hdr_tbl, l_xla_line_tbl LIMIT 5000;
10458
10459 FORALL x IN 1..l_result_code_tbl.count
10460 UPDATE xla_validation_lines_gt vl
10461 SET vl.funds_status_code = l_result_code_tbl(x)
10462 WHERE vl.ae_header_id = l_xla_hdr_tbl(x) AND
10463 vl.ae_line_num = l_xla_line_tbl(x) AND
10464 vl.ledger_id = p_ledgerid;
10465
10466 -- ====== FND LOG ======
10467 psa_utils.debug_other_string(g_state_level, l_full_path, ' BCTRL -> Updated '||sql%rowcount||
10468 ' rows.');
10469 -- ====== FND LOG ======
10470
10471 EXIT when c_get_result_codes%notfound;
10472 END LOOP;
10473
10474 CLOSE c_get_result_codes;
10475 END LOOP;
10476
10477 -- Bug 5397349 .. End
10478
10479 -- Update PSA_BC_XLA_EVENTS_GT table with result_code
10480
10481 -- ====== FND LOG ======
10482 psa_utils.debug_other_string(g_state_level, l_full_path, ' BCTRL -> Update result_code '||
10483 'of psa_bc_xla_events_gt');
10484 -- ====== FND LOG ======
10485
10486 -- this update will ensure that only valid xla events
10487 -- provided for FUNDS CHECK (meant xla_ae_headers rows updated with funds_status_code)
10488 -- are updated with appropiate status. Events NOT picked by funds checker will be updated with XLA_ERROR.
10489 UPDATE psa_bc_xla_events_gt eg
10490 SET result_code = (SELECT decode(min(funds_status_code),
10491 'T', 'FATAL',
10492 'S', 'SUCCESS',
10493 'A', 'ADVISORY',
10494 'F', 'FAIL',
10495 'P', 'PARTIAL',
10496 'XLA_ERROR')
10497 FROM xla_ae_headers_gt hg
10498 WHERE hg.event_id = eg.event_id)
10499 where eg.event_id in (select event_id from xla_ae_headers_gt);
10500
10501 -- ====== FND LOG ======
10502 psa_utils.debug_other_string(g_state_level, l_full_path, ' BCTRL -> Updated valid funds check '||sql%rowcount||
10503 ' rows.');
10504 -- ====== FND LOG ======
10505
10506 -- Update global variable for packet_id to the first packet_id
10507
10508 PSA_BC_XLA_PVT.G_PACKET_ID := l_packets(1);
10509
10510 -- ====== FND LOG ======
10511 psa_utils.debug_other_string(g_state_level, l_full_path, ' BCTRL -> Updated '||
10512 ' PSA_BC_XLA_PVT.G_PACKET_ID to '||PSA_BC_XLA_PVT.G_PACKET_ID);
10513 -- ====== FND LOG ======
10514
10515 -- ====== FND LOG ======
10516 psa_utils.debug_other_string(g_state_level, l_full_path, ' BCTRL -> l_t_status_cnt = '||l_t_status_cnt);
10517 psa_utils.debug_other_string(g_state_level, l_full_path, ' BCTRL -> l_s_status_cnt = '||l_s_status_cnt);
10518 psa_utils.debug_other_string(g_state_level, l_full_path, ' BCTRL -> l_a_status_cnt = '||l_a_status_cnt);
10519 psa_utils.debug_other_string(g_state_level, l_full_path, ' BCTRL -> l_f_status_cnt = '||l_f_status_cnt);
10520 psa_utils.debug_other_string(g_state_level, l_full_path, ' BCTRL -> l_p_status_cnt = '||l_p_status_cnt);
10521 -- ====== FND LOG ======
10522
10523 -- Bug 4918234
10524 /* We need to update the related events stauses which were NOT picked up by funds checker.
10525 e.g. PA BURDEN lines failed XLA validation but corresponding PO RAW passed XLA validation
10526 or PO RAW line failed XLA validation but corresponding PA BURDEN lines passed XLA validation.
10527 */
10528
10529 -- Update Funds_Status_Code column in XLA_AE_HEADERS_GT
10530 UPDATE xla_ae_headers_gt
10531 SET funds_status_code = 'F'
10532 WHERE event_id IN (
10533 SELECT event_id
10534 FROM psa_bc_alloc_gt
10535 WHERE status_code <> 'P');
10536
10537 IF(SQL%ROWCOUNT<> 0) THEN
10538 -- ====== FND LOG ======
10539 psa_utils.debug_other_string(g_state_level,l_full_path, ' BCTRL -> Updated '||sql%rowcount||' rows of XLA_AE_HEADERS_GT with fail status.');
10540 -- ====== FND LOG ======
10541 END IF;
10542
10543 -- Update Funds_Status_Code column in XLA_VALIDATION_LINES_GT
10544 UPDATE xla_validation_lines_gt vl
10545 SET vl.funds_status_code = 'F76'
10546 WHERE event_id IN (
10547 SELECT event_id
10548 FROM psa_bc_alloc_gt
10549 WHERE status_code <> 'P');
10550
10551 IF(SQL%ROWCOUNT<> 0) THEN
10552 -- ====== FND LOG ======
10553 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.');
10554 -- ====== FND LOG ======
10555 END IF;
10556
10557 --================== Allocation Attributes second level of validation Logic start =================
10558 /* Now we need to check that the transaction rows which are put for funds operation,
10559 have been successfully processed by funds checker. If atleast one transaction row
10560 for a hierarchy fails funds operation, we will fail all the related transaction rows in
10561 GL_BC_PACKETS with the status F77. */
10562
10563 IF (l_alloc_used = 'Y') THEN
10564 FOR h in c_get_hierarchy_id
10565 LOOP
10566 OPEN c_chk_funds_hier(h.hierarchy_id,
10567 l_session_id,
10568 l_serial_id);
10569 FETCH c_chk_funds_hier INTO dummy;
10570 IF (c_chk_funds_hier%FOUND) THEN
10571 CLOSE c_chk_funds_hier;
10572 -- update the statuses of gl_bc_packets
10573 -- related rows to 'F' Failed or 'R' Rejected.
10574 UPDATE gl_bc_packets
10575 SET status_code = decode(PSA_BC_XLA_PVT.G_BC_MODE, 'C', 'F',
10576 'M', 'F',
10577 'R', 'R',
10578 'P', 'R')
10579 ,result_code = 'F77'
10580 WHERE (ae_header_id, ae_line_num, event_id)
10581 IN (SELECT ae_header_id, ae_line_num, event_id
10582 FROM psa_bc_alloc_gt
10583 WHERE hierarchy_id = h.hierarchy_id
10584 )
10585 AND status_code NOT IN ('F', 'R')
10586 AND session_id = l_session_id
10587 AND serial_id = l_serial_id;
10588 -- ====== FND LOG ======
10589 psa_utils.debug_other_string(g_state_level, l_full_path, 'BCTRL -> Updated '
10590 ||sql%rowcount||' rows of GL_BC_PACKETS with F77 status.');
10591 -- ====== FND LOG ======
10592
10593 ELSE
10594 CLOSE c_chk_funds_hier;
10595 END IF;
10596 END LOOP;
10597
10598 UPDATE xla_ae_headers_gt
10599 SET funds_status_code = decode(PSA_BC_XLA_PVT.G_BC_MODE, 'C', 'F',
10600 'M', 'F',
10601 'R', 'F',
10602 'P', 'F')
10603 WHERE ae_header_id IN (SELECT ae_header_id
10604 FROM gl_bc_packets
10605 WHERE result_code = 'F77'
10606 AND session_id = l_session_id
10607 AND serial_id = l_serial_id) and
10608 ledger_id = p_ledgerid;
10609 -- ====== FND LOG ======
10610 psa_utils.debug_other_string(g_state_level, l_full_path, ' BCTRL -> Updated funds_status_code of '||
10611 sql%rowcount||' rows successfully of XLA_AE_HEADERS_GT. ');
10612 -- ====== FND LOG ======
10613
10614 UPDATE xla_validation_lines_gt vl
10615 SET vl.funds_status_code = 'F77'
10616 WHERE vl.ae_header_id IN (SELECT ae_header_id
10617 FROM gl_bc_packets
10618 WHERE result_code = 'F77'
10619 AND session_id = l_session_id
10620 AND serial_id = l_serial_id) and
10621 vl.ledger_id = p_ledgerid;
10622 -- ====== FND LOG ======
10623 psa_utils.debug_other_string(g_state_level, l_full_path, ' BCTRL -> Updated '||sql%rowcount||
10624 ' rows of XLA_VALIDATION_LINES_GT with F77 status.');
10625 -- ====== FND LOG ======
10626
10627 -- Reinitialize all the count variables
10628 l_s_status_cnt := 0;
10629 l_a_status_cnt := 0;
10630 l_f_status_cnt := 0;
10631 l_p_status_cnt := 0;
10632 l_t_status_cnt := 0;
10633 l_ret_code := NULL;
10634
10635 -- Now for each packet evaluate the return_code
10636 FOR i IN 1..l_packets.COUNT
10637 LOOP
10638 OPEN c_pkt_retcode(l_packets(i));
10639 FETCH c_pkt_retcode INTO l_ret_code;
10640 CLOSE c_pkt_retcode;
10641 IF (l_ret_code IN ('S', 'A')) THEN
10642 l_s_status_cnt := nvl(l_s_status_cnt, 0) + 1;
10643 ELSIF (l_ret_code = 'F') THEN
10644 l_f_status_cnt := nvl(l_f_status_cnt, 0) + 1;
10645 ELSIF (l_ret_code = 'P') THEN
10646 l_p_status_cnt := nvl(l_p_status_cnt, 0) + 1;
10647 ELSIF (l_ret_code = 'T') OR (l_ret_code IS NULL) THEN
10648 l_t_status_cnt := nvl(l_t_status_cnt, 0) + 1;
10649 END IF;
10650 l_ret_code := NULL;
10651 END LOOP;
10652
10653 END IF;
10654
10655 --================== Allocation Attributes second level of validation Logic end =================
10656
10657 -- Set the return code
10658 IF nvl(l_t_status_cnt , 0) > 0 THEN
10659 p_return_code := 'T';
10660 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
10661 p_return_code := 'P';
10662 ELSIF nvl(l_f_status_cnt, 0) > 0 THEN
10663 p_return_code := 'F';
10664 ELSE
10665 p_return_code := 'S';
10666 END IF;
10667
10668 -- ====== FND LOG ======
10669 psa_utils.debug_other_string(g_state_level, l_full_path, ' BCTRL -> Return_code = '||p_return_code);
10670 psa_utils.debug_other_string(g_state_level, l_full_path, ' BCTRL -> Return TRUE');
10671 -- ====== FND LOG ======
10672
10673 -- Invoke the DEBUG_XLA procedure to transfer data from XLA global temporary tables to
10674 -- PSA regular tables.
10675
10676 debug_xla ( 'BUDGETARY_CONTROL_END' );
10677
10678 psa_utils.debug_other_string(g_state_level,l_full_path,'Cleaning up psa_bc_alloc_gt Table');
10679 DELETE FROM psa_bc_alloc_gt; --For bug 7607496
10680 psa_utils.debug_other_string(g_state_level,l_full_path, ' Deleted Rows -> ' || SQL%ROWCOUNT);
10681
10682 return TRUE;
10683
10684 EXCEPTION
10685 WHEN GL_BC_PACKETS_EMPTY THEN
10686 IF (NOT g_xla_debug) THEN
10687 -- ====== FND LOG ======
10688 psa_utils.debug_other_string(g_error_level,l_full_path, ' BCTRL -> XLA_AE_HEADERS_GT DUMP');
10689 psa_utils.debug_other_string(g_error_level,l_full_path, ' -------------------- ');
10690
10691 -- ====== FND LOG ======
10692 FOR h IN debug_xla_ae_headers_gt
10693 LOOP
10694 -- ====== FND LOG ======
10695 psa_utils.debug_other_string(g_error_level,l_full_path, ' EVENT_ID = '||h.event_id||' , '||
10696 ' AE_HEADER_ID = '||h.ae_header_id||' , '||
10697 ' LEDGER_ID = '||h.ledger_id||' , '||
10698 ' EVENT_TYPE_CODE = '||h.event_type_code||' , '||
10699 ' FUNDS_STATUS_CODE = '||h.funds_status_code||' , '||
10700 ' ACCOUNTING_ENTRY_STATUS_CODE = '||h.accounting_entry_status_code||' , '||
10701 ' BALANCE_TYPE_CODE = '||h.balance_type_code);
10702 -- ====== FND LOG ======
10703 END LOOP;
10704 -- ====== FND LOG ======
10705 psa_utils.debug_other_string(g_error_level,l_full_path, ' BCTRL -> XLA_AE_LINES_GT DUMP');
10706 psa_utils.debug_other_string(g_error_level,l_full_path, ' -------------------- ');
10707
10708
10709 -- ====== FND LOG ======
10710 FOR x IN debug_xla_ae_lines_gt
10711 LOOP
10712 -- ====== FND LOG ======
10713 psa_utils.debug_other_string(g_error_level,l_full_path, ' EVENT_ID = '||x.event_id||' , '||
10714 ' AE_HEADER_ID = '||x.ae_header_id||' , '||
10715 ' AE_LINE_NUM = '||x.ae_line_num);
10716 -- ====== FND LOG ======
10717 END LOOP;
10718
10719 -- ====== FND LOG ======
10720 psa_utils.debug_other_string(g_error_level,l_full_path, ' BCTRL -> XLA_VALIDATION_LINES_GT DUMP');
10721 psa_utils.debug_other_string(g_error_level,l_full_path, ' ---------------------------- ');
10722 -- ====== FND LOG ======
10723 FOR y IN debug_xla_val_lines_gt
10724 LOOP
10725 -- ====== FND LOG ======
10726 psa_utils.debug_other_string(g_error_level,l_full_path, ' AE_HEADER_ID = '||y.ae_header_id||' , '||
10727 ' AE_LINE_NUM = '||y.ae_line_num||' , '||
10728 ' PERIOD_NAME = '||y.period_name||' , '||
10729 ' ACCOUNTING_ENTRY_STATUS_CODE = '||y.accounting_entry_status_code||' , '||
10730 ' BALANCING_LINE_TYPE = '||y.balancing_line_type);
10731 -- ====== FND LOG ======
10732 END LOOP;
10733
10734 -- ====== FND LOG ======
10735 psa_utils.debug_other_string(g_error_level,l_full_path, ' BCTRL -> XLA_EVENTS_GT DUMP');
10736 psa_utils.debug_other_string(g_error_level,l_full_path, ' ---------------------------- ');
10737 -- ====== FND LOG ======
10738 FOR z in debug_xla_events_gt
10739 LOOP
10740 -- ====== FND LOG ======
10741 psa_utils.debug_other_string(g_error_level,l_full_path, ' APPLICATION_ID = '||z.application_id||' , '||
10742 ' EVENT_ID = '||z.event_id||' , '||
10743 ' EVENT_DATE = '||z.event_date||' , '||
10744 ' EVENT_TYPE_CODE = '||z.event_type_code||' , '||
10745 ' REFERENCE_NUM_1 = '||z.reference_num_1);
10746 -- ====== FND LOG ======
10747 END LOOP;
10748 -- ====== FND LOG ======
10749 psa_utils.debug_other_string(g_error_level,l_full_path, ' BCTRL -> XLA_PSA_BC_LINES_V DUMP');
10750 psa_utils.debug_other_string(g_error_level,l_full_path,' --------------------------------------- ');
10751 -- ====== FND LOG ======
10752 FOR v in debug_xla_psa_bc_v
10753 LOOP
10754 -- ====== FND LOG ======
10755 psa_utils.debug_other_string(g_error_level,l_full_path, ' EVENT_ID = '||v.event_id||' , '||
10756 ' AE_HEADER_ID = '||v.ae_header_id||' , '||
10757 ' AE_LINE_NUM = '||v.ae_line_num||' , '||
10758 ' ENTITY_ID = '||v.entity_id||' , '||
10759 ' PERIOD_NAME = '||v.period_name);
10760 -- ====== FND LOG ======
10761 END LOOP;
10762
10763 -- ====== FND LOG ======
10764 psa_utils.debug_other_string(g_error_level,l_full_path, ' BCTRL -> PSA_BC_ALLOC_GT DUMP');
10765 psa_utils.debug_other_string(g_error_level,l_full_path,' --------------------------------------- ');
10766 -- ====== FND LOG ======
10767 FOR p in debug_psa_bc_alloc_gt
10768 LOOP
10769 -- ====== FND LOG ======
10770 psa_utils.debug_other_string(g_error_level,l_full_path, ' HIERARCHY_ID = '||p.hierarchy_id||' , '||
10771 ' EVENT_ID = '||p.event_id||' , '||
10772 ' AE_HEADER_ID = '||p.ae_header_id||' , '||
10773 ' AE_LINE_NUM = '||p.ae_line_num||' , '||
10774 ' STATUS_CODE = '||p.status_code);
10775 -- ====== FND LOG ======
10776 END LOOP;
10777
10778
10779 select count(*) into l_var_1
10780 from xla_psa_bc_lines_v;
10781 -- ====== FND LOG ======
10782 psa_utils.debug_other_string(g_error_level,l_full_path, ' XLA_PSA_BC_LINES_V returns '||l_var_1||' rows. ');
10783 psa_utils.debug_other_string(g_error_level,l_full_path, ' Error: Populated 0 rows in gl_bc_packets.');
10784 psa_utils.debug_other_string(g_error_level,l_full_path, ' RETURN -> FALSE');
10785 -- ====== FND LOG ======
10786 p_return_code := 'T';
10787 return FALSE;
10788 END IF;
10789 WHEN OTHERS THEN
10790 -- ====== FND LOG ======
10791 psa_utils.debug_other_string(g_excep_level, l_full_path, ' BCTRL -> Exception Raised: '||sqlerrm);
10792 psa_utils.debug_other_string(g_excep_level, l_full_path, ' BCTRL -> Return_code = T');
10793 psa_utils.debug_other_string(g_excep_level, l_full_path, ' BCTRL -> Return FALSE');
10794 -- ====== FND LOG ======
10795 p_return_code := 'T';
10796 return FALSE;
10797
10798 END budgetary_control;
10799
10800 /*===========================================================================================+
10801 | Procedure : SYNC_XLA_ERRORS |
10802 | Description : This API is invoked by SLA in package |
10803 | XLA_JE_VALIDATION_PKG.UNDO_FUNDS_RESERVE to synchronize budgetary control |
10804 | errors in secondary/reporting ledgers reported by SLA. |
10805 +===========================================================================================*/
10806
10807 PROCEDURE sync_xla_errors (p_failed_ldgr_array IN num_rec,
10808 p_failed_evnt_array IN num_rec)
10809 IS
10810
10811
10812 CURSOR c_success_evt_exists IS
10813 SELECT 'Successful event exists in the current packet'
10814 FROM gl_bc_packets
10815 WHERE event_id IN (SELECT event_id
10816 FROM psa_bc_xla_events_gt
10817 )
10818 AND application_id = PSA_BC_XLA_PVT.g_application_id
10819 AND status_code = 'A';
10820
10821 dummy VARCHAR2(100);
10822 l_success_evt_exist VARCHAR2(1);
10823 l_f81_cnt NUMBER;
10824 l_f82_cnt NUMBER;
10825
10826 -- ========================= FND LOG ===========================
10827 l_full_path VARCHAR2(100);
10828 -- ========================= FND LOG ===========================
10829
10830 BEGIN
10831
10832 l_f81_cnt := 0;
10833 l_f82_cnt := 0;
10834 l_full_path := g_path || 'sync_xla_errors';
10835
10836 -- ====== FND LOG ======
10837 psa_utils.debug_other_string(g_state_level, l_full_path, ' BCTRL -> p_failed_ldgr_array.COUNT: '|| p_failed_ldgr_array.COUNT);
10838 psa_utils.debug_other_string(g_state_level, l_full_path, ' BCTRL -> p_failed_evnt_array.COUNT: '|| p_failed_evnt_array.COUNT);
10839 -- ====== FND LOG ======
10840
10841 FORALL i IN 1..p_failed_ldgr_array.COUNT
10842 UPDATE gl_bc_packets
10843 SET status_code = decode(PSA_BC_XLA_PVT.G_BC_MODE, 'C', 'F',
10844 'M', 'F',
10845 'R', 'R',
10846 'P', 'R')
10847 ,result_code = 'F81'
10848 WHERE event_id = p_failed_evnt_array(i)
10849 AND application_id = PSA_BC_XLA_PVT.g_application_id
10850 AND ledger_id = p_failed_ldgr_array(i)
10851 AND status_code NOT IN ('F', 'R');
10852
10853 l_f81_cnt := SQL%ROWCOUNT;
10854
10855 -- ====== FND LOG ======
10856 psa_utils.debug_other_string(g_state_level, l_full_path, ' BCTRL -> Updated GL_BC_PACKETS '||l_f81_cnt||
10857 ' rows to F81 status.');
10858 -- ====== FND LOG ======
10859
10860
10861 FORALL j IN 1..p_failed_evnt_array.COUNT
10862 UPDATE gl_bc_packets
10863 SET status_code = decode(PSA_BC_XLA_PVT.G_BC_MODE, 'C', 'F',
10864 'M', 'F',
10865 'R', 'R',
10866 'P', 'R')
10867 ,result_code = 'F82'
10868 WHERE event_id = p_failed_evnt_array(j)
10869 AND application_id = PSA_BC_XLA_PVT.g_application_id
10870 AND status_code NOT IN ('F', 'R');
10871
10872 l_f82_cnt := SQL%ROWCOUNT;
10873
10874 -- ====== FND LOG ======
10875 psa_utils.debug_other_string(g_state_level, l_full_path, ' BCTRL -> Updated GL_BC_PACKETS '||l_f82_cnt||
10876 ' rows to F82 status.');
10877 -- ====== FND LOG ======
10878
10879 -- This check is to ensure that if we have not updated any GL_BC_PACKETS
10880 -- row/s to failure then there was a genuine failure in GL_BC_PACKETS
10881 -- and we should not overwrite that failure with XLA_ERROR for the event.
10882 -- We need to retain the original failure status reported and inform the same
10883 -- back to the calling transaction.
10884
10885 IF (l_f81_cnt <> 0 OR l_f82_cnt <> 0) THEN
10886 FORALL k IN 1..p_failed_evnt_array.COUNT
10887 UPDATE psa_bc_xla_events_gt
10888 SET result_code = 'XLA_ERROR'
10889 WHERE event_id = p_failed_evnt_array(k)
10890 AND result_code <> 'XLA_ERROR';
10891
10892 -- ====== FND LOG ======
10893 psa_utils.debug_other_string(g_state_level, l_full_path, ' BCTRL -> Updated PSA_BC_XLA_EVENTS_GT '||sql%rowcount||
10894 ' rows to XLA_ERROR status.');
10895 -- ====== FND LOG ======
10896
10897 END IF;
10898
10899 OPEN c_success_evt_exists;
10900 FETCH c_success_evt_exists INTO dummy;
10901 IF (c_success_evt_exists%FOUND) THEN
10902 l_success_evt_exist := 'Y';
10903 CLOSE c_success_evt_exists;
10904 ELSE
10905 l_success_evt_exist := 'N';
10906 CLOSE c_success_evt_exists;
10907 END IF;
10908
10909 IF (l_success_evt_exist = 'N') THEN
10910
10911 UPDATE gl_bc_packet_arrival_order
10912 SET affect_funds_flag = 'N'
10913 WHERE affect_funds_flag = 'Y'
10914 AND packet_id IN ( SELECT packet_id
10915 FROM gl_bc_packets bc
10916 WHERE event_id IN ( SELECT event_id
10917 FROM psa_bc_xla_events_gt
10918 )
10919 AND application_id = PSA_BC_XLA_PVT.g_application_id
10920 AND result_code IN ('F81', 'F82')
10921 ) ;
10922
10923 -- ====== FND LOG ======
10924 psa_utils.debug_other_string(g_state_level, l_full_path, ' BCTRL -> Updated GL_BC_PACKET_ARRIVAL_ORDER '||sql%rowcount||
10925 ' rows.');
10926 -- ====== FND LOG ======
10927
10928
10929 END IF;
10930
10931
10932 EXCEPTION
10933 WHEN OTHERS THEN
10934 -- ====== FND LOG ======
10935 psa_utils.debug_other_string(g_excep_level, l_full_path, ' BCTRL -> Exception Raised: '||sqlerrm);
10936 -- ====== FND LOG ======
10937 IF (c_success_evt_exists%ISOPEN) THEN
10938 CLOSE c_success_evt_exists;
10939 END IF;
10940 APP_EXCEPTION.RAISE_EXCEPTION;
10941
10942 END sync_xla_errors;
10943
10944
10945 END PSA_FUNDS_CHECKER_PKG;
10946