DBA Data[Home] [Help]

PACKAGE BODY: APPS.XLA_08407_AAD_S_000013_BC_PKG

Source


1 PACKAGE BODY XLA_08407_AAD_S_000013_BC_PKG AS
2 --
3 /*======================================================================+
4 |                Copyright (c) 1997 Oracle Corporation                  |
5 |                       Redwood Shores, CA, USA                         |
6 |                         All rights reserved.                          |
7 +=======================================================================+
8 | Package Name                                                          |
9 |     XLA_08407_AAD_S_000013_BC_PKG                                     |
10 |                                                                       |
11 | DESCRIPTION                                                           |
12 |     Package generated From Product Accounting Definition              |
13 |      Name    : CC Encumbrance Common                                  |
14 |      Code    : CC_ENC_COMMON                                          |
15 |      Owner   : PRODUCT                                                |
16 |      Version :                                                        |
17 |      AMB Context Code: DEFAULT                                        |
18 | HISTORY                                                               |
19 |     Generated at 06-11-2008 at 01:11:03 by user ANONYMOUS             |
20 +=======================================================================*/
21 --
22 --
23 TYPE t_rec_array_event IS RECORD
24    (array_legal_entity_id                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num
25    ,array_entity_id                      XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num
26    ,array_entity_code                    XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L
27    ,array_transaction_num                XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L
28    ,array_event_id                       xla_number_array_type --XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num
29    ,array_class_code                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L
30    ,array_event_type                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L
31    ,array_event_number                   XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num
32    ,array_event_date                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date
33    ,array_reference_num_1                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num
34    ,array_reference_num_2                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num
35    ,array_reference_num_3                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num
36    ,array_reference_num_4                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num
37    ,array_reference_char_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L
38    ,array_reference_char_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L
39    ,array_reference_char_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L
40    ,array_reference_char_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L
41    ,array_reference_date_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date
42    ,array_reference_date_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date
43    ,array_reference_date_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date
44    ,array_reference_date_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date
45    ,array_event_created_by               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V100L
46    );
47 --
48 type t_array_value_num is table of number index by varchar2(30);
49 type t_array_value_char is table of varchar2(240) index by varchar2(30);
50 type t_array_value_date is table of date index by varchar2(30);
51 
52 type t_rec_value is record
53  (array_value_num     t_array_value_num
54  ,array_value_char    t_array_value_char
55  ,array_value_date    t_array_value_date);
56 
57 type t_array_event is table of  t_rec_value index by binary_integer;
58 
59 g_array_event   t_array_event;
60 
61 --=============================================================================
62 --               *********** Diagnostics **********
63 --=============================================================================
64 
65 g_diagnostics_mode          VARCHAR2(1);
66 g_last_hdr_idx              NUMBER;        -- 4262811 MPA
67 g_hdr_extract_count         PLS_INTEGER;
68 
69 --=============================================================================
70 --               *********** Local Trace Routine **********
71 --=============================================================================
72 
73 C_LEVEL_STATEMENT     CONSTANT NUMBER := FND_LOG.LEVEL_STATEMENT;
74 C_LEVEL_PROCEDURE     CONSTANT NUMBER := FND_LOG.LEVEL_PROCEDURE;
75 C_LEVEL_EVENT         CONSTANT NUMBER := FND_LOG.LEVEL_EVENT;
76 C_LEVEL_EXCEPTION     CONSTANT NUMBER := FND_LOG.LEVEL_EXCEPTION;
77 C_LEVEL_ERROR         CONSTANT NUMBER := FND_LOG.LEVEL_ERROR;
78 C_LEVEL_UNEXPECTED    CONSTANT NUMBER := FND_LOG.LEVEL_UNEXPECTED;
79 
80 C_LEVEL_LOG_DISABLED  CONSTANT NUMBER := 99;
81 C_DEFAULT_MODULE      CONSTANT VARCHAR2(240) := 'xla.plsql.XLA_08407_AAD_S_000013_BC_PKG';
82 
83 C_CHAR                CONSTANT       VARCHAR2(30) := fnd_global.local_chr(12); -- 4219869 Business flow
84 C_NUM                 CONSTANT       NUMBER       := 9.99E125;                 -- 4219869 Business flow
85 
86 g_log_level           NUMBER;
87 g_log_enabled         BOOLEAN;
88 
89 PROCEDURE trace
90            (p_msg                        IN VARCHAR2
91            ,p_level                      IN NUMBER
92            ,p_module                     IN VARCHAR2 ) IS
93 BEGIN
94 ----------------------------------------------------------------------------
95 -- Following is for FND log.
96 ----------------------------------------------------------------------------
97 IF (p_msg IS NULL AND p_level >= g_log_level) THEN
98           fnd_log.message(p_level, p_module);
99 ELSIF p_level >= g_log_level THEN
100           fnd_log.string(p_level, p_module, p_msg);
101 END IF;
102 
103 EXCEPTION
104        WHEN xla_exceptions_pkg.application_exception THEN
105           RAISE;
106        WHEN OTHERS THEN
107           xla_exceptions_pkg.raise_message
108              (p_location   => 'XLA_08407_AAD_S_000013_BC_PKG.trace');
109 END trace;
110 
111 --
112 --+============================================+
113 --|                                            |
114 --|  PRIVATE  PROCEDURES/FUNCTIONS             |
115 --|                                            |
116 --+============================================+
117 --
118 
119 --
120 /*======================================================================+
121 |                                                                       |
122 | Private Function                                                      |
123 |    ValidateLookupMeaning                                              |
124 |                                                                       |
125 +======================================================================*/
126 FUNCTION ValidateLookupMeaning(
127   p_meaning                IN VARCHAR2
128 , p_lookup_code            IN VARCHAR2
129 , p_lookup_type            IN VARCHAR2
130 , p_source_code            IN VARCHAR2
131 , p_source_type_code       IN VARCHAR2
132 , p_source_application_id  IN INTEGER
133 )
134 RETURN VARCHAR2
135 IS
136 l_log_module         VARCHAR2(240);
137 BEGIN
138 IF g_log_enabled THEN
139       l_log_module := C_DEFAULT_MODULE||'.ValidateLookupMeaning';
140 END IF;
141 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
142       trace
143          (p_msg      => 'BEGIN of ValidateLookupMeaning'
144          ,p_level    => C_LEVEL_PROCEDURE
145          ,p_module   => l_log_module);
146 END IF;
147 --
148 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
149     trace
150          (p_msg      => 'p_source_code = '|| p_source_code||
151                         ' - p_source_type_code = '|| p_source_type_code||
152                         ' - p_source_application_id = '|| p_source_application_id||
153                         ' - p_lookup_code = '|| p_lookup_code||
154                         ' - p_lookup_type = '|| p_lookup_type||
155                         ' - p_meaning = '|| p_meaning
156          ,p_level    => C_LEVEL_PROCEDURE
157          ,p_module   => l_log_module);
158 
159 END IF;
160 
161 IF p_lookup_code IS NOT NULL AND p_meaning IS NULL THEN
162    xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
163    xla_accounting_err_pkg. build_message
164                (p_appli_s_name            => 'XLA'
165                ,p_msg_name                => 'XLA_AP_NO_LOOKUP_MEANING'
166                ,p_token_1                 => 'SOURCE_NAME'
167                ,p_value_1                 =>  xla_ae_sources_pkg.GetSourceName(
168                                                            p_source_code
169                                                          , p_source_type_code
170                                                          , p_source_application_id
171                                                          )
172                ,p_token_2                 => 'LOOKUP_CODE'
173                ,p_value_2                 =>  p_lookup_code
174                ,p_token_3                 => 'LOOKUP_TYPE'
175                ,p_value_3                 =>  p_lookup_type
176                ,p_token_4                 => 'PRODUCT_NAME'
177                ,p_value_4                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
178                ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
179                ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
180                ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
181        );
182 
183    IF (C_LEVEL_ERROR >= g_log_level) THEN
184            trace
185                 (p_msg      => 'ERROR: XLA_AP_NO_LOOKUP_MEANING'
186                 ,p_level    => C_LEVEL_ERROR
187                 ,p_module   => l_log_module);
188    END IF;
189 END IF;
190 
191 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
192         trace
193           (p_msg      => 'END of ValidateLookupMeaning'
194           ,p_level    => C_LEVEL_PROCEDURE
195           ,p_module   => l_log_module);
196 END IF;
197 RETURN p_meaning;
198 EXCEPTION
199 WHEN xla_exceptions_pkg.application_exception THEN
200   RETURN p_meaning;
201 WHEN OTHERS  THEN
202    xla_exceptions_pkg.raise_message
203            (p_location => 'XLA_08407_AAD_S_000013_BC_PKG.ValidateLookupMeaning');
204        --
205 END ValidateLookupMeaning;
206 --
207 --
208 
209 FUNCTION GetMeaning (
210   p_flex_value_set_id               IN INTEGER
211 , p_flex_value                      IN VARCHAR2
212 , p_source_code                     IN VARCHAR2
213 , p_source_type_code                IN VARCHAR2
214 , p_source_application_id           IN INTEGER
215 )
216 RETURN VARCHAR2
217 IS
218 BEGIN
219 --
220 RETURN NULL ;
221 --
222 EXCEPTION
223   WHEN xla_exceptions_pkg.application_exception THEN
224       RAISE;
225   WHEN OTHERS THEN
226        xla_exceptions_pkg.raise_message
227            (p_location => 'XLA_08407_AAD_S_000013_BC_PKG.GetMeaning');
228 END GetMeaning;
229 --
230 
231 ---------------------------------------
232 --
233 -- PRIVATE FUNCTION
234 --         Description_1
235 --
236 ---------------------------------------
237 FUNCTION Description_1 (
238   p_application_id      IN NUMBER
239 , p_ae_header_id        IN NUMBER DEFAULT NULL 
240 --TRANSACTION DESCRIPTION
241  , p_source_1            IN VARCHAR2
242 )
243 RETURN VARCHAR2
244 IS
245 l_component_type        VARCHAR2(80)   ;
246 l_component_code        VARCHAR2(30)   ;
247 l_component_type_code   VARCHAR2(1)    ;
248 l_component_appl_id     INTEGER        ;
249 l_amb_context_code      VARCHAR2(30)   ;
250 l_ledger_language       VARCHAR2(30)   ;
251 l_source                VARCHAR2(1996) ;
252 l_description           VARCHAR2(2000) ;
253 l_log_module            VARCHAR2(240)  ;
254 BEGIN
255 IF g_log_enabled THEN
256       l_log_module := C_DEFAULT_MODULE||'.Description_1';
257 END IF;
258 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
259       trace
260          (p_msg      => 'BEGIN of Description_1'
261          ,p_level    => C_LEVEL_PROCEDURE
262          ,p_module   => l_log_module);
263 END IF;
264 
265 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
266 l_component_type        := 'AMB_DESCRIPTION';
267 l_component_code        := 'CC_COMMON_DTL_DESC';
268 l_component_type_code   := 'S';
269 l_component_appl_id     :=  8407;
270 l_amb_context_code      := 'DEFAULT';
271 l_source                := NULL;
272 l_description           := NULL;
273 
274 
275   
276   l_source := SUBSTR(p_source_1,1,1996);
277   IF l_source IS NOT NULL THEN
278     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
279     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
280   END IF; 
281  l_description := SUBSTR(l_description,1,1996);
282   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
283         trace
284            (p_msg      => 'END of Description_1'
285            ,p_level    => C_LEVEL_PROCEDURE
286            ,p_module   => l_log_module);
287 
288   END IF;
289   RETURN l_description;
290 
291 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
292       trace
293          (p_msg      => 'END of Description_1'
294          ,p_level    => C_LEVEL_PROCEDURE
295          ,p_module   => l_log_module);
296 END IF;
297 RETURN NULL;
298 EXCEPTION
299   WHEN VALUE_ERROR THEN
300      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
301             trace
302                (p_msg      => 'ERROR: '||sqlerrm
303                ,p_level    => C_LEVEL_EXCEPTION
304                ,p_module   => l_log_module);
305      END IF;
306      RAISE;
307  WHEN xla_exceptions_pkg.application_exception THEN
308       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
309       trace
310          (p_msg      => 'ERROR: '||sqlerrm
311          ,p_level    => C_LEVEL_EXCEPTION
312          ,p_module   => l_log_module);
313       END IF;
314       RAISE;
315  WHEN OTHERS THEN
316        xla_exceptions_pkg.raise_message
317            (p_location => 'XLA_08407_AAD_S_000013_BC_PKG.Description_1');
318 END Description_1;
319 
320 ---------------------------------------
321 --
322 -- PRIVATE FUNCTION
323 --         Description_2
324 --
325 ---------------------------------------
326 FUNCTION Description_2 (
330  , p_source_2            IN VARCHAR2
327   p_application_id      IN NUMBER
328 , p_ae_header_id        IN NUMBER DEFAULT NULL 
329 --HEADER DESC
331 --REFERENCE 4
332  , p_source_3            IN VARCHAR2
333 --VERSION NUM
334  , p_source_4            IN VARCHAR2
335 )
336 RETURN VARCHAR2
337 IS
338 l_component_type        VARCHAR2(80)   ;
339 l_component_code        VARCHAR2(30)   ;
340 l_component_type_code   VARCHAR2(1)    ;
341 l_component_appl_id     INTEGER        ;
342 l_amb_context_code      VARCHAR2(30)   ;
343 l_ledger_language       VARCHAR2(30)   ;
344 l_source                VARCHAR2(1996) ;
345 l_description           VARCHAR2(2000) ;
346 l_log_module            VARCHAR2(240)  ;
347 BEGIN
348 IF g_log_enabled THEN
349       l_log_module := C_DEFAULT_MODULE||'.Description_2';
350 END IF;
351 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
352       trace
353          (p_msg      => 'BEGIN of Description_2'
354          ,p_level    => C_LEVEL_PROCEDURE
355          ,p_module   => l_log_module);
356 END IF;
357 
358 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
359 l_component_type        := 'AMB_DESCRIPTION';
360 l_component_code        := 'CC_COMMON_HDR_DESC';
361 l_component_type_code   := 'S';
362 l_component_appl_id     :=  8407;
363 l_amb_context_code      := 'DEFAULT';
364 l_source                := NULL;
365 l_description           := NULL;
366 
367 
368   
369   l_source := SUBSTR(p_source_2,1,1996);
370   IF l_source IS NOT NULL THEN
371     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
372     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
373   END IF;  
374  IF 
375 l_ledger_language = 'US' THEN
376     l_description :=  SUBSTR(CONCAT(l_description,':'),1,2000);
377     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
378  END IF;   
379   l_source := SUBSTR(p_source_3,1,1996);
380   IF l_source IS NOT NULL THEN
381     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
382     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
383   END IF;  
384  IF 
385 l_ledger_language = 'US' THEN
386     l_description :=  SUBSTR(CONCAT(l_description,':'),1,2000);
387     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
388  END IF;   
389   l_source := SUBSTR(p_source_4,1,1996);
390   IF l_source IS NOT NULL THEN
391     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
392     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
393   END IF; 
394  l_description := SUBSTR(l_description,1,1996);
395   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
396         trace
397            (p_msg      => 'END of Description_2'
398            ,p_level    => C_LEVEL_PROCEDURE
399            ,p_module   => l_log_module);
400 
401   END IF;
402   RETURN l_description;
403 
404 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
405       trace
406          (p_msg      => 'END of Description_2'
407          ,p_level    => C_LEVEL_PROCEDURE
408          ,p_module   => l_log_module);
409 END IF;
410 RETURN NULL;
411 EXCEPTION
412   WHEN VALUE_ERROR THEN
413      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
414             trace
415                (p_msg      => 'ERROR: '||sqlerrm
416                ,p_level    => C_LEVEL_EXCEPTION
417                ,p_module   => l_log_module);
418      END IF;
419      RAISE;
420  WHEN xla_exceptions_pkg.application_exception THEN
421       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
422       trace
423          (p_msg      => 'ERROR: '||sqlerrm
424          ,p_level    => C_LEVEL_EXCEPTION
425          ,p_module   => l_log_module);
426       END IF;
427       RAISE;
428  WHEN OTHERS THEN
429        xla_exceptions_pkg.raise_message
430            (p_location => 'XLA_08407_AAD_S_000013_BC_PKG.Description_2');
431 END Description_2;
432 
433 ---------------------------------------
434 --
435 -- PRIVATE FUNCTION
436 --         AcctDerRule_3
437 --
438 ---------------------------------------
439 FUNCTION AcctDerRule_3 (
440   p_application_id              IN NUMBER
441 , p_ae_header_id                IN NUMBER
442 , p_side                        IN VARCHAR2 
443 --CODE COMBINATION ID
444  , p_source_5            IN NUMBER
445 , x_transaction_coa_id         OUT NOCOPY NUMBER
446 , x_accounting_coa_id          OUT NOCOPY NUMBER
447 , x_value_type_code            OUT NOCOPY VARCHAR2
448 )
449 RETURN NUMBER
450 IS
451 l_component_type       VARCHAR2(80)  ;
452 l_component_code       VARCHAR2(30)  ;
453 l_component_type_code  VARCHAR2(1)   ;
454 l_component_appl_id    INTEGER       ;
455 l_amb_context_code     VARCHAR2(30)  ;
456 l_log_module           VARCHAR2(240) ;
457 l_output_value         NUMBER        ;
458 BEGIN
459 IF g_log_enabled THEN
460       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_3';
461 END IF;
462 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
463       trace
464          (p_msg      => 'BEGIN of AcctDerRule_3'
465          ,p_level    => C_LEVEL_PROCEDURE
466          ,p_module   => l_log_module);
467 END IF;
468 --
472 l_component_appl_id      :=  8407;
469 l_component_type         := 'AMB_ADR';
470 l_component_code         := 'CC_COMMON_ADR';
471 l_component_type_code    := 'S';
473 l_amb_context_code       := 'DEFAULT';
474 x_transaction_coa_id     :=  null;
475 x_accounting_coa_id      :=  null;
476 --
477 
478  --
479   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
480       trace
481          (p_msg      => 'END of AcctDerRule_3'
482          ,p_level    => C_LEVEL_PROCEDURE
483          ,p_module   => l_log_module);
484   END IF;
485   x_value_type_code := 'S';
486   l_output_value    := TO_NUMBER(TO_NUMBER(p_source_5));
487   RETURN l_output_value;
488 
489 --
490 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
491       trace
492          (p_msg      => 'END of AcctDerRule_3(invalid)'
493          ,p_level    => C_LEVEL_PROCEDURE
494          ,p_module   => l_log_module);
495 END IF;
496 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
497 x_value_type_code := null;
498 l_output_value    := null;
499 xla_accounting_err_pkg.build_message
500                  (p_appli_s_name            => 'XLA'
501                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
502                  ,p_token_1                 => 'COMPONENT_NAME'
503                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
504                                                             l_component_type
505                                                           , l_component_code
506                                                           , l_component_type_code
507                                                           , l_component_appl_id
508                                                           , l_amb_context_code
509                                                           )
510                  ,p_token_2                 => 'OWNER'
511                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
512                                                         'XLA_OWNER_TYPE'
513                                                         ,l_component_type_code
514                                                         )
515                  ,p_token_3                 => 'PAD_NAME'
516                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
517                  ,p_token_4                 => 'PAD_OWNER'
518                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
519                                                         'XLA_OWNER_TYPE'
520                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
521                                                         )
522                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
523                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
524                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
525                  ,p_ae_header_id            => NULL
526 );
527 RETURN l_output_value;
528 EXCEPTION
529   WHEN xla_exceptions_pkg.application_exception THEN
530       RAISE;
531   WHEN OTHERS THEN
532        xla_exceptions_pkg.raise_message
533            (p_location => 'XLA_08407_AAD_S_000013_BC_PKG.AcctDerRule_3');
534 END AcctDerRule_3;
535 --
536 
537 ---------------------------------------
538 --
539 -- PRIVATE FUNCTION
540 --         AcctLineType_4
541 --
542 ---------------------------------------
543 PROCEDURE AcctLineType_4 (
544   p_application_id        IN NUMBER
545  ,p_event_id              IN NUMBER
546  ,p_calculate_acctd_flag  IN VARCHAR2
547  ,p_calculate_g_l_flag    IN VARCHAR2
548  ,p_actual_flag           IN OUT VARCHAR2
549  ,p_balance_type_code     OUT VARCHAR2
550  ,p_gain_or_loss_ref      OUT VARCHAR2
551  
552 --TRANSACTION DESCRIPTION
553  , p_source_1            IN VARCHAR2
554 --CODE COMBINATION ID
555  , p_source_5            IN NUMBER
556 --CC FUNC CR AMT
557  , p_source_6            IN NUMBER
558 --PROJECT LINE
559  , p_source_7            IN VARCHAR2
560 --CC ACCT LINE ID
561  , p_source_8            IN NUMBER
562 --DOCUMENT TYPE
563  , p_source_9            IN VARCHAR2
564 --CC FUNC AMT
565  , p_source_10            IN NUMBER
566 --CURRENCY CODE
567  , p_source_11            IN VARCHAR2
568 )
569 IS
570 
571 l_component_type              VARCHAR2(80);
572 l_component_code              VARCHAR2(30);
573 l_component_type_code         VARCHAR2(1);
574 l_component_appl_id           INTEGER;
575 l_amb_context_code            VARCHAR2(30);
576 l_entity_code                 VARCHAR2(30);
577 l_event_class_code            VARCHAR2(30);
578 l_ae_header_id                NUMBER;
579 l_event_type_code             VARCHAR2(30);
580 l_line_definition_code        VARCHAR2(30);
581 l_line_definition_owner_code  VARCHAR2(1);
582 --
583 -- adr variables
584 l_segment                     VARCHAR2(30);
585 l_ccid                        NUMBER;
586 l_adr_transaction_coa_id      NUMBER;
587 l_adr_accounting_coa_id       NUMBER;
588 l_adr_flexfield_segment_code  VARCHAR2(30);
589 l_adr_flex_value_set_id       NUMBER;
590 l_adr_value_type_code         VARCHAR2(30);
591 l_adr_value_combination_id    NUMBER;
592 l_adr_value_segment_code      VARCHAR2(30);
593 
597 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
594 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
595 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
596 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
598 
599 -- 4262811 Variables ------------------------------------------------------------------------------------------
600 l_entered_amt_idx             NUMBER;
601 l_accted_amt_idx              NUMBER;
602 l_acc_rev_flag                VARCHAR2(1);
603 l_accrual_line_num            NUMBER;
604 l_tmp_amt                     NUMBER;
605 l_acc_rev_natural_side_code   VARCHAR2(1);
606 
607 l_num_entries                 NUMBER;
608 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
609 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
610 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
611 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
612 l_recog_line_1                NUMBER;
613 l_recog_line_2                NUMBER;
614 
615 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
616 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
617 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
618 
619 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
620 
621 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
622 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
623 
624 ---------------------------------------------------------------------------------------------------------------
625 
626 
627 --
628 -- bulk performance
629 --
630 l_balance_type_code           VARCHAR2(1);
631 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
632 l_log_module                  VARCHAR2(240);
633 
634 --
635 -- Upgrade strategy
636 --
637 l_actual_upg_option           VARCHAR2(1);
638 l_enc_upg_option           VARCHAR2(1);
639 
640 --
641 BEGIN
642 --
643 IF g_log_enabled THEN
644       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_4';
645 END IF;
646 --
647 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
648 
649       trace
650          (p_msg      => 'BEGIN of AcctLineType_4'
651          ,p_level    => C_LEVEL_PROCEDURE
652          ,p_module   => l_log_module);
653 
654 END IF;
655 --
656 l_component_type             := 'AMB_JLT';
657 l_component_code             := 'CC_CONTRACT_CMT_CR';
658 l_component_type_code        := 'S';
659 l_component_appl_id          :=  8407;
660 l_amb_context_code           := 'DEFAULT';
661 l_entity_code                := 'CC_CONTRACTS';
662 l_event_class_code           := 'CC_CONTRACT_CMT';
663 l_event_type_code            := 'CC_CONTRACT_CMT_ALL';
664 l_line_definition_owner_code := 'S';
665 l_line_definition_code       := 'CC_CONTRACT_CMT_CMN';
666 --
667 l_balance_type_code          := 'E';
668 l_segment                     := NULL;
669 l_ccid                        := NULL;
670 l_adr_transaction_coa_id      := NULL;
671 l_adr_accounting_coa_id       := NULL;
672 l_adr_flexfield_segment_code  := NULL;
673 l_adr_flex_value_set_id       := NULL;
674 l_adr_value_type_code         := NULL;
675 l_adr_value_combination_id    := NULL;
676 l_adr_value_segment_code      := NULL;
677 
678 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
679 l_bflow_class_code           := '';    -- 4219869 Business Flow
680 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
681 l_budgetary_control_flag     := 'Y';
682 
683 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
684 l_bflow_applied_to_amt       := NULL; -- 5132302
685 l_entered_amt_idx            := NULL;          -- 4262811
686 l_accted_amt_idx             := NULL;          -- 4262811
687 l_acc_rev_flag               := NULL;          -- 4262811
688 l_accrual_line_num           := NULL;          -- 4262811
689 l_tmp_amt                    := NULL;          -- 4262811
690 --
691  
692 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
693     l_balance_type_code <> 'B' THEN
694 IF p_source_6 IS NOT NULL AND 
695 NVL(p_source_7,'
696 ') <>  'Y'
697  THEN 
698 
699    --
700    XLA_AE_LINES_PKG.SetNewLine;
701 
702    p_balance_type_code          := l_balance_type_code;
703    -- set the flag so later we will know whether the gain loss line needs to be created
704    
705    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
706      p_actual_flag :='A';
707    END IF;
708 
709    --
710    -- bulk performance
711    --
712    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
713                                       p_header_num   => 0); -- 4262811
714    --
715    -- set accounting line options
716    --
717    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
718            p_natural_side_code          => 'C'
719          , p_gain_or_loss_flag          => 'N'
720          , p_gl_transfer_mode_code      => 'D'
721          , p_acct_entry_type_code       => 'E'
725    --
722          , p_switch_side_flag           => 'N'
723          , p_merge_duplicate_code       => 'N'
724          );
726    l_acc_rev_natural_side_code := 'D';  -- 4262811
727    -- 
728    --
729    -- set accounting line type info
730    --
731    xla_ae_lines_pkg.SetAcctLineType
732       (p_component_type             => l_component_type
733       ,p_event_type_code            => l_event_type_code
734       ,p_line_definition_owner_code => l_line_definition_owner_code
735       ,p_line_definition_code       => l_line_definition_code
736       ,p_accounting_line_code       => l_component_code
737       ,p_accounting_line_type_code  => l_component_type_code
738       ,p_accounting_line_appl_id    => l_component_appl_id
739       ,p_amb_context_code           => l_amb_context_code
740       ,p_entity_code                => l_entity_code
741       ,p_event_class_code           => l_event_class_code);
742    --
743    -- set accounting class
744    --
745    xla_ae_lines_pkg.SetAcctClass(
746            p_accounting_class_code  => 'PURCHASE_ORDER'
747          , p_ae_header_id           => l_ae_header_id
748          );
749 
750    --
751    -- set rounding class
752    --
753    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
754                       'PURCHASE_ORDER';
755 
756    --
757    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
758    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
759    --
760    -- bulk performance
761    --
762    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
763 
764    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
765       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
766 
767    -- 4955764
768    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
769       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
770 
771    -- 4458381 Public Sector Enh
772       XLA_AE_LINES_PKG.g_rec_lines.array_encumbrance_type_id(XLA_AE_LINES_PKG.g_LineNumber) := 1000;
773    --
774    -- set accounting attributes for the line type
775    --
776    l_entered_amt_idx := 3;
777    l_accted_amt_idx  := 5;
778    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
779    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
780    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_8);
781    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
782    l_rec_acct_attrs.array_char_value(2)  := p_source_9;
783    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
784    l_rec_acct_attrs.array_num_value(3)  := p_source_10;
785    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
786    l_rec_acct_attrs.array_char_value(4)  := p_source_11;
787    l_rec_acct_attrs.array_acct_attr_code(5) := 'LEDGER_AMOUNT';
788    l_rec_acct_attrs.array_num_value(5)  := p_source_10;
789 
790    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
791    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
792 
793    ---------------------------------------------------------------------------------------------------------------
794    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
795    ---------------------------------------------------------------------------------------------------------------
796    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
797 
798    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
799    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
800 
801    IF xla_accounting_cache_pkg.GetValueChar
802          (p_source_code         => 'LEDGER_CATEGORY_CODE'
803          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
804    AND l_bflow_method_code = 'PRIOR_ENTRY'
805 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
806    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
807          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
808        )
809    THEN
810          xla_ae_lines_pkg.BflowUpgEntry
811            (p_business_method_code    => l_bflow_method_code
812            ,p_business_class_code     => l_bflow_class_code
813            ,p_balance_type            => l_balance_type_code);
814    ELSE
815       NULL;
816 -- No business flow processing for business flow method of NONE.
817    END IF;
818 
819    --
820    -- call analytical criteria
821    --
822    
823    --
824    -- call description
825    --
826    
827 xla_ae_lines_pkg.SetLineDescription(
828    p_ae_header_id => l_ae_header_id
829   ,p_description  => Description_1 (
830      p_application_id         => p_application_id
831    , p_ae_header_id           => l_ae_header_id 
832 , p_source_1 => p_source_1
833    )
834 );
835 
836 
837    --
838    -- call ADRs
839    -- Bug 4922099
840    --
841    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
845    THEN
842         (NVL(l_actual_upg_option, 'N') = 'O') OR
843         (NVL(l_enc_upg_option, 'N') = 'O')
844       )
846    NULL;
847    --
848    --
849    
850   l_ccid := AcctDerRule_3(
851            p_application_id           => p_application_id
852          , p_ae_header_id             => l_ae_header_id 
853 , p_source_5 => p_source_5
854          , x_transaction_coa_id       => l_adr_transaction_coa_id
855          , x_accounting_coa_id        => l_adr_accounting_coa_id
856          , x_value_type_code          => l_adr_value_type_code
857          , p_side                     => 'NA'
858    );
859 
860    xla_ae_lines_pkg.set_ccid(
861     p_code_combination_id          => l_ccid
862   , p_value_type_code              => l_adr_value_type_code
863   , p_transaction_coa_id           => l_adr_transaction_coa_id
864   , p_accounting_coa_id            => l_adr_accounting_coa_id
865   , p_adr_code                     => 'CC_COMMON_ADR'
866   , p_adr_type_code                => 'S'
867   , p_component_type               => l_component_type
868   , p_component_code               => l_component_code
869   , p_component_type_code          => l_component_type_code
870   , p_component_appl_id            => l_component_appl_id
871   , p_amb_context_code             => l_amb_context_code
872   , p_side                         => 'NA'
873   );
874 
875 
876    --
877    --
878    END IF;
879    --
880    -- Bug 4922099
881    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
882           (NVL(l_enc_upg_option, 'N') = 'O')
883         ) AND
884         (l_bflow_method_code = 'PRIOR_ENTRY')
885       )
886    THEN
887       IF
888       --
889       1 = 2
890       --
891       THEN
892       xla_accounting_err_pkg.build_message
893                                     (p_appli_s_name            => 'XLA'
894                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
895                                     ,p_token_1                 => 'LINE_NUMBER'
896                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
897                                     ,p_token_2                 => 'LINE_TYPE_NAME'
898                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
899                                                                              l_component_type
900                                                                             ,l_component_code
901                                                                             ,l_component_type_code
902                                                                             ,l_component_appl_id
903                                                                             ,l_amb_context_code
904                                                                             ,l_entity_code
905                                                                             ,l_event_class_code
906                                                                            )
907                                     ,p_token_3                 => 'OWNER'
908                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
909                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
910                                                                           ,p_lookup_code    => l_component_type_code
911                                                                          )
912                                     ,p_token_4                 => 'PRODUCT_NAME'
913                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
914                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
915                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
916                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
917                                     ,p_ae_header_id            =>  NULL
918                                        );
919 
920         IF (C_LEVEL_ERROR>= g_log_level) THEN
921                  trace
922                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
923                       ,p_level    => C_LEVEL_ERROR
924                       ,p_module   => l_log_module);
925         END IF;
926       END IF;
927    END IF;
928    --
929    --
930    ------------------------------------------------------------------------------------------------
931    -- 4219869 Business Flow
932    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
933    -- Prior Entry.  Currently, the following code is always generated.
934    ------------------------------------------------------------------------------------------------
935    XLA_AE_LINES_PKG.ValidateCurrentLine;
936 
937    ------------------------------------------------------------------------------------
938    -- 4219869 Business Flow
939    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
940    ------------------------------------------------------------------------------------
941    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
942 
946    ----------------------------------------------------------------------------------
943    ----------------------------------------------------------------------------------
944    -- 4219869 Business Flow
945    -- Update journal entry status -- Need to generate this within IF <condition>
947    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
948          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
949          ,p_balance_type_code => l_balance_type_code
950          );
951 
952    -------------------------------------------------------------------------------------------
953    -- 4262811 - Generate the Accrual Reversal lines
954    -------------------------------------------------------------------------------------------
955    BEGIN
956       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
957                               (g_array_event(p_event_id).array_value_num('header_index'));
958       IF l_acc_rev_flag IS NULL THEN
959          l_acc_rev_flag := 'N';
960       END IF;
961    EXCEPTION
962       WHEN OTHERS THEN
963          l_acc_rev_flag := 'N';
964    END;
965    --
966    IF (l_acc_rev_flag = 'Y') THEN
967 
968        -- 4645092  ------------------------------------------------------------------------------
969        -- To allow MPA report to determine if it should generate report process
970        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
971        ------------------------------------------------------------------------------------------
972 
973        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
974        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
975 
976        --
977        -- Update the line information that should be overwritten
978        --
979        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
980                                          p_header_num   => 1);
981        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
982 
983        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
984 
985        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
986           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
987        END IF;
988 
989       --
990       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
991       --
992       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
993           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
994       ELSE
995           ---------------------------------------------------------------------------------------------------
996           -- 4262811a Switch Sign
997           ---------------------------------------------------------------------------------------------------
998           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
999           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
1000                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
1001           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
1002                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
1003           -- 5132302
1004           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
1005                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
1006 
1007       END IF;
1008 
1009       -- 4955764
1010       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
1011       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
1012 
1013 
1014       XLA_AE_LINES_PKG.ValidateCurrentLine;
1015       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
1016 
1017       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
1018                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
1019                ,p_balance_type_code => l_balance_type_code);
1020 
1021    END IF;
1022 
1023    -----------------------------------------------------------------------------------------
1024    -- 4262811 Multiperiod Accounting
1025    -----------------------------------------------------------------------------------------
1026      -- No MPA option is assigned.
1027 
1028 
1029 END IF;
1030 END IF;
1031 --
1032 
1033 --
1034 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1035    trace
1036       (p_msg      => 'END of AcctLineType_4'
1037       ,p_level    => C_LEVEL_PROCEDURE
1038       ,p_module   => l_log_module);
1039 END IF;
1040 --
1041 EXCEPTION
1042   WHEN xla_exceptions_pkg.application_exception THEN
1043       RAISE;
1044   WHEN OTHERS THEN
1045        xla_exceptions_pkg.raise_message
1046            (p_location => 'XLA_08407_AAD_S_000013_BC_PKG.AcctLineType_4');
1047 END AcctLineType_4;
1048 --
1049 
1050 ---------------------------------------
1051 --
1052 -- PRIVATE FUNCTION
1053 --         AcctLineType_5
1054 --
1055 ---------------------------------------
1056 PROCEDURE AcctLineType_5 (
1057   p_application_id        IN NUMBER
1058  ,p_event_id              IN NUMBER
1059  ,p_calculate_acctd_flag  IN VARCHAR2
1063  ,p_gain_or_loss_ref      OUT VARCHAR2
1060  ,p_calculate_g_l_flag    IN VARCHAR2
1061  ,p_actual_flag           IN OUT VARCHAR2
1062  ,p_balance_type_code     OUT VARCHAR2
1064  
1065 --TRANSACTION DESCRIPTION
1066  , p_source_1            IN VARCHAR2
1067 --CODE COMBINATION ID
1068  , p_source_5            IN NUMBER
1069 --PROJECT LINE
1070  , p_source_7            IN VARCHAR2
1071 --CC ACCT LINE ID
1072  , p_source_8            IN NUMBER
1073 --DOCUMENT TYPE
1074  , p_source_9            IN VARCHAR2
1075 --CC FUNC AMT
1076  , p_source_10            IN NUMBER
1077 --CURRENCY CODE
1078  , p_source_11            IN VARCHAR2
1079 --CC FUNC DR AMT
1080  , p_source_12            IN NUMBER
1081 --APPLIED TO APPL ID
1082  , p_source_13            IN NUMBER
1083 --APPLIED TO DIST LINK TYPE
1084  , p_source_14            IN VARCHAR2
1085 --APPLIED TO ENTITY CODE
1086  , p_source_15            IN VARCHAR2
1087 --APPLIED TO DIST ID 1
1088  , p_source_16            IN NUMBER
1089 --APPLIED TO HEADER ID 1
1090  , p_source_17            IN NUMBER
1091 )
1092 IS
1093 
1094 l_component_type              VARCHAR2(80);
1095 l_component_code              VARCHAR2(30);
1096 l_component_type_code         VARCHAR2(1);
1097 l_component_appl_id           INTEGER;
1098 l_amb_context_code            VARCHAR2(30);
1099 l_entity_code                 VARCHAR2(30);
1100 l_event_class_code            VARCHAR2(30);
1101 l_ae_header_id                NUMBER;
1102 l_event_type_code             VARCHAR2(30);
1103 l_line_definition_code        VARCHAR2(30);
1104 l_line_definition_owner_code  VARCHAR2(1);
1105 --
1106 -- adr variables
1107 l_segment                     VARCHAR2(30);
1108 l_ccid                        NUMBER;
1109 l_adr_transaction_coa_id      NUMBER;
1110 l_adr_accounting_coa_id       NUMBER;
1111 l_adr_flexfield_segment_code  VARCHAR2(30);
1112 l_adr_flex_value_set_id       NUMBER;
1113 l_adr_value_type_code         VARCHAR2(30);
1114 l_adr_value_combination_id    NUMBER;
1115 l_adr_value_segment_code      VARCHAR2(30);
1116 
1117 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
1118 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
1119 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
1120 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
1121 
1122 -- 4262811 Variables ------------------------------------------------------------------------------------------
1123 l_entered_amt_idx             NUMBER;
1124 l_accted_amt_idx              NUMBER;
1125 l_acc_rev_flag                VARCHAR2(1);
1126 l_accrual_line_num            NUMBER;
1127 l_tmp_amt                     NUMBER;
1128 l_acc_rev_natural_side_code   VARCHAR2(1);
1129 
1130 l_num_entries                 NUMBER;
1131 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
1132 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
1133 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
1134 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
1135 l_recog_line_1                NUMBER;
1136 l_recog_line_2                NUMBER;
1137 
1138 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
1139 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
1140 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
1141 
1142 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
1143 
1144 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
1145 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
1146 
1147 ---------------------------------------------------------------------------------------------------------------
1148 
1149 
1150 --
1151 -- bulk performance
1152 --
1153 l_balance_type_code           VARCHAR2(1);
1154 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
1155 l_log_module                  VARCHAR2(240);
1156 
1157 --
1158 -- Upgrade strategy
1159 --
1160 l_actual_upg_option           VARCHAR2(1);
1161 l_enc_upg_option           VARCHAR2(1);
1162 
1163 --
1164 BEGIN
1165 --
1166 IF g_log_enabled THEN
1167       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_5';
1168 END IF;
1169 --
1170 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1171 
1172       trace
1173          (p_msg      => 'BEGIN of AcctLineType_5'
1174          ,p_level    => C_LEVEL_PROCEDURE
1175          ,p_module   => l_log_module);
1176 
1177 END IF;
1178 --
1179 l_component_type             := 'AMB_JLT';
1180 l_component_code             := 'CC_CONTRACT_CMT_DR';
1181 l_component_type_code        := 'S';
1182 l_component_appl_id          :=  8407;
1183 l_amb_context_code           := 'DEFAULT';
1184 l_entity_code                := 'CC_CONTRACTS';
1185 l_event_class_code           := 'CC_CONTRACT_CMT';
1186 l_event_type_code            := 'CC_CONTRACT_CMT_ALL';
1187 l_line_definition_owner_code := 'S';
1188 l_line_definition_code       := 'CC_CONTRACT_CMT_CMN';
1189 --
1190 l_balance_type_code          := 'E';
1191 l_segment                     := NULL;
1192 l_ccid                        := NULL;
1193 l_adr_transaction_coa_id      := NULL;
1194 l_adr_accounting_coa_id       := NULL;
1198 l_adr_value_combination_id    := NULL;
1195 l_adr_flexfield_segment_code  := NULL;
1196 l_adr_flex_value_set_id       := NULL;
1197 l_adr_value_type_code         := NULL;
1199 l_adr_value_segment_code      := NULL;
1200 
1201 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
1202 l_bflow_class_code           := 'PO_ENCUMBRANCE';    -- 4219869 Business Flow
1203 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
1204 l_budgetary_control_flag     := 'Y';
1205 
1206 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
1207 l_bflow_applied_to_amt       := NULL; -- 5132302
1208 l_entered_amt_idx            := NULL;          -- 4262811
1209 l_accted_amt_idx             := NULL;          -- 4262811
1210 l_acc_rev_flag               := NULL;          -- 4262811
1211 l_accrual_line_num           := NULL;          -- 4262811
1212 l_tmp_amt                    := NULL;          -- 4262811
1213 --
1214  
1215 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
1216     l_balance_type_code <> 'B' THEN
1217 IF p_source_12 IS NOT NULL AND 
1218 NVL(p_source_7,'
1219 ') <>  'Y'
1220  THEN 
1221 
1222    --
1223    XLA_AE_LINES_PKG.SetNewLine;
1224 
1225    p_balance_type_code          := l_balance_type_code;
1226    -- set the flag so later we will know whether the gain loss line needs to be created
1227    
1228    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
1229      p_actual_flag :='A';
1230    END IF;
1231 
1232    --
1233    -- bulk performance
1234    --
1235    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
1236                                       p_header_num   => 0); -- 4262811
1237    --
1238    -- set accounting line options
1239    --
1240    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
1241            p_natural_side_code          => 'D'
1242          , p_gain_or_loss_flag          => 'N'
1243          , p_gl_transfer_mode_code      => 'D'
1244          , p_acct_entry_type_code       => 'E'
1245          , p_switch_side_flag           => 'N'
1246          , p_merge_duplicate_code       => 'N'
1247          );
1248    --
1249    l_acc_rev_natural_side_code := 'C';  -- 4262811
1250    -- 
1251    --
1252    -- set accounting line type info
1253    --
1254    xla_ae_lines_pkg.SetAcctLineType
1255       (p_component_type             => l_component_type
1256       ,p_event_type_code            => l_event_type_code
1257       ,p_line_definition_owner_code => l_line_definition_owner_code
1258       ,p_line_definition_code       => l_line_definition_code
1259       ,p_accounting_line_code       => l_component_code
1260       ,p_accounting_line_type_code  => l_component_type_code
1261       ,p_accounting_line_appl_id    => l_component_appl_id
1262       ,p_amb_context_code           => l_amb_context_code
1263       ,p_entity_code                => l_entity_code
1264       ,p_event_class_code           => l_event_class_code);
1265    --
1266    -- set accounting class
1267    --
1268    xla_ae_lines_pkg.SetAcctClass(
1269            p_accounting_class_code  => 'PURCHASE_ORDER'
1270          , p_ae_header_id           => l_ae_header_id
1271          );
1272 
1273    --
1274    -- set rounding class
1275    --
1276    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
1277                       'PURCHASE_ORDER';
1278 
1279    --
1280    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
1281    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
1282    --
1283    -- bulk performance
1284    --
1285    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
1286 
1287    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
1288       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
1289 
1290    -- 4955764
1291    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
1292       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
1293 
1294    -- 4458381 Public Sector Enh
1295       XLA_AE_LINES_PKG.g_rec_lines.array_encumbrance_type_id(XLA_AE_LINES_PKG.g_LineNumber) := 1001;
1296    --
1297    -- set accounting attributes for the line type
1298    --
1299    l_entered_amt_idx := 8;
1300    l_accted_amt_idx  := 10;
1301    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
1302    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
1303    l_rec_acct_attrs.array_num_value(1)  := p_source_13;
1304    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
1305    l_rec_acct_attrs.array_char_value(2)  := p_source_14;
1306    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
1307    l_rec_acct_attrs.array_char_value(3)  := p_source_15;
1308    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
1309    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_16);
1310    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
1311    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_17);
1312    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
1316    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
1313    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_8);
1314    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
1315    l_rec_acct_attrs.array_char_value(7)  := p_source_9;
1317    l_rec_acct_attrs.array_num_value(8)  := p_source_10;
1318    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
1319    l_rec_acct_attrs.array_char_value(9)  := p_source_11;
1320    l_rec_acct_attrs.array_acct_attr_code(10) := 'LEDGER_AMOUNT';
1321    l_rec_acct_attrs.array_num_value(10)  := p_source_10;
1322 
1323    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
1324    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
1325 
1326    ---------------------------------------------------------------------------------------------------------------
1327    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
1328    ---------------------------------------------------------------------------------------------------------------
1329    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
1330 
1331    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
1332    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
1333 
1334    IF xla_accounting_cache_pkg.GetValueChar
1335          (p_source_code         => 'LEDGER_CATEGORY_CODE'
1336          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
1337    AND l_bflow_method_code = 'PRIOR_ENTRY'
1338 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
1339    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
1340          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
1341        )
1342    THEN
1343          xla_ae_lines_pkg.BflowUpgEntry
1344            (p_business_method_code    => l_bflow_method_code
1345            ,p_business_class_code     => l_bflow_class_code
1346            ,p_balance_type            => l_balance_type_code);
1347    ELSE
1348       NULL;
1349 -- No business flow processing for business flow method of NONE.
1350    END IF;
1351 
1352    --
1353    -- call analytical criteria
1354    --
1355    
1356    --
1357    -- call description
1358    --
1359    
1360 xla_ae_lines_pkg.SetLineDescription(
1361    p_ae_header_id => l_ae_header_id
1362   ,p_description  => Description_1 (
1363      p_application_id         => p_application_id
1364    , p_ae_header_id           => l_ae_header_id 
1365 , p_source_1 => p_source_1
1366    )
1367 );
1368 
1369 
1370    --
1371    -- call ADRs
1372    -- Bug 4922099
1373    --
1374    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
1375         (NVL(l_actual_upg_option, 'N') = 'O') OR
1376         (NVL(l_enc_upg_option, 'N') = 'O')
1377       )
1378    THEN
1379    NULL;
1380    --
1381    --
1382    
1383   l_ccid := AcctDerRule_3(
1384            p_application_id           => p_application_id
1385          , p_ae_header_id             => l_ae_header_id 
1386 , p_source_5 => p_source_5
1387          , x_transaction_coa_id       => l_adr_transaction_coa_id
1388          , x_accounting_coa_id        => l_adr_accounting_coa_id
1389          , x_value_type_code          => l_adr_value_type_code
1390          , p_side                     => 'NA'
1391    );
1392 
1393    xla_ae_lines_pkg.set_ccid(
1394     p_code_combination_id          => l_ccid
1395   , p_value_type_code              => l_adr_value_type_code
1396   , p_transaction_coa_id           => l_adr_transaction_coa_id
1397   , p_accounting_coa_id            => l_adr_accounting_coa_id
1398   , p_adr_code                     => 'CC_COMMON_ADR'
1399   , p_adr_type_code                => 'S'
1400   , p_component_type               => l_component_type
1401   , p_component_code               => l_component_code
1402   , p_component_type_code          => l_component_type_code
1403   , p_component_appl_id            => l_component_appl_id
1404   , p_amb_context_code             => l_amb_context_code
1405   , p_side                         => 'NA'
1406   );
1407 
1408 
1409    --
1410    --
1411    END IF;
1412    --
1413    -- Bug 4922099
1414    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
1415           (NVL(l_enc_upg_option, 'N') = 'O')
1416         ) AND
1417         (l_bflow_method_code = 'PRIOR_ENTRY')
1418       )
1419    THEN
1420       IF
1421       --
1422       1 = 2
1423       --
1424       THEN
1425       xla_accounting_err_pkg.build_message
1426                                     (p_appli_s_name            => 'XLA'
1427                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
1428                                     ,p_token_1                 => 'LINE_NUMBER'
1429                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
1430                                     ,p_token_2                 => 'LINE_TYPE_NAME'
1431                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
1432                                                                              l_component_type
1436                                                                             ,l_amb_context_code
1433                                                                             ,l_component_code
1434                                                                             ,l_component_type_code
1435                                                                             ,l_component_appl_id
1437                                                                             ,l_entity_code
1438                                                                             ,l_event_class_code
1439                                                                            )
1440                                     ,p_token_3                 => 'OWNER'
1441                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
1442                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
1443                                                                           ,p_lookup_code    => l_component_type_code
1444                                                                          )
1445                                     ,p_token_4                 => 'PRODUCT_NAME'
1446                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
1447                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
1448                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
1449                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
1450                                     ,p_ae_header_id            =>  NULL
1451                                        );
1452 
1453         IF (C_LEVEL_ERROR>= g_log_level) THEN
1454                  trace
1455                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
1456                       ,p_level    => C_LEVEL_ERROR
1457                       ,p_module   => l_log_module);
1458         END IF;
1459       END IF;
1460    END IF;
1461    --
1462    --
1463    ------------------------------------------------------------------------------------------------
1464    -- 4219869 Business Flow
1465    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
1466    -- Prior Entry.  Currently, the following code is always generated.
1467    ------------------------------------------------------------------------------------------------
1468    XLA_AE_LINES_PKG.ValidateCurrentLine;
1469 
1470    ------------------------------------------------------------------------------------
1471    -- 4219869 Business Flow
1472    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
1473    ------------------------------------------------------------------------------------
1474    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
1475 
1476    ----------------------------------------------------------------------------------
1477    -- 4219869 Business Flow
1478    -- Update journal entry status -- Need to generate this within IF <condition>
1479    ----------------------------------------------------------------------------------
1480    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
1481          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
1482          ,p_balance_type_code => l_balance_type_code
1483          );
1484 
1485    -------------------------------------------------------------------------------------------
1486    -- 4262811 - Generate the Accrual Reversal lines
1487    -------------------------------------------------------------------------------------------
1488    BEGIN
1489       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
1490                               (g_array_event(p_event_id).array_value_num('header_index'));
1491       IF l_acc_rev_flag IS NULL THEN
1492          l_acc_rev_flag := 'N';
1493       END IF;
1494    EXCEPTION
1495       WHEN OTHERS THEN
1496          l_acc_rev_flag := 'N';
1497    END;
1498    --
1499    IF (l_acc_rev_flag = 'Y') THEN
1500 
1501        -- 4645092  ------------------------------------------------------------------------------
1502        -- To allow MPA report to determine if it should generate report process
1503        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
1504        ------------------------------------------------------------------------------------------
1505 
1506        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
1507        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
1508 
1509        --
1510        -- Update the line information that should be overwritten
1511        --
1512        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
1513                                          p_header_num   => 1);
1514        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
1515 
1516        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
1517 
1518        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
1519           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
1520        END IF;
1521 
1522       --
1523       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
1524       --
1525       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
1529           -- 4262811a Switch Sign
1526           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
1527       ELSE
1528           ---------------------------------------------------------------------------------------------------
1530           ---------------------------------------------------------------------------------------------------
1531           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
1532           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
1533                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
1534           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
1535                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
1536           -- 5132302
1537           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
1538                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
1539 
1540       END IF;
1541 
1542       -- 4955764
1543       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
1544       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
1545 
1546 
1547       XLA_AE_LINES_PKG.ValidateCurrentLine;
1548       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
1549 
1550       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
1551                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
1552                ,p_balance_type_code => l_balance_type_code);
1553 
1554    END IF;
1555 
1556    -----------------------------------------------------------------------------------------
1557    -- 4262811 Multiperiod Accounting
1558    -----------------------------------------------------------------------------------------
1559      -- No MPA option is assigned.
1560 
1561 
1562 END IF;
1563 END IF;
1564 --
1565 
1566 --
1567 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1568    trace
1569       (p_msg      => 'END of AcctLineType_5'
1570       ,p_level    => C_LEVEL_PROCEDURE
1571       ,p_module   => l_log_module);
1572 END IF;
1573 --
1574 EXCEPTION
1575   WHEN xla_exceptions_pkg.application_exception THEN
1576       RAISE;
1577   WHEN OTHERS THEN
1578        xla_exceptions_pkg.raise_message
1579            (p_location => 'XLA_08407_AAD_S_000013_BC_PKG.AcctLineType_5');
1580 END AcctLineType_5;
1581 --
1582 
1583 ---------------------------------------
1584 --
1585 -- PRIVATE FUNCTION
1586 --         AcctLineType_6
1587 --
1588 ---------------------------------------
1589 PROCEDURE AcctLineType_6 (
1590   p_application_id        IN NUMBER
1591  ,p_event_id              IN NUMBER
1592  ,p_calculate_acctd_flag  IN VARCHAR2
1593  ,p_calculate_g_l_flag    IN VARCHAR2
1594  ,p_actual_flag           IN OUT VARCHAR2
1595  ,p_balance_type_code     OUT VARCHAR2
1596  ,p_gain_or_loss_ref      OUT VARCHAR2
1597  
1598 --TRANSACTION DESCRIPTION
1599  , p_source_1            IN VARCHAR2
1600 --CODE COMBINATION ID
1601  , p_source_5            IN NUMBER
1602 --CC FUNC CR AMT
1603  , p_source_6            IN NUMBER
1604 --PROJECT LINE
1605  , p_source_7            IN VARCHAR2
1606 --CC ACCT LINE ID
1607  , p_source_8            IN NUMBER
1608 --DOCUMENT TYPE
1609  , p_source_9            IN VARCHAR2
1610 --CC FUNC AMT
1611  , p_source_10            IN NUMBER
1612 --CURRENCY CODE
1613  , p_source_11            IN VARCHAR2
1614 )
1615 IS
1616 
1617 l_component_type              VARCHAR2(80);
1618 l_component_code              VARCHAR2(30);
1619 l_component_type_code         VARCHAR2(1);
1620 l_component_appl_id           INTEGER;
1621 l_amb_context_code            VARCHAR2(30);
1622 l_entity_code                 VARCHAR2(30);
1623 l_event_class_code            VARCHAR2(30);
1624 l_ae_header_id                NUMBER;
1625 l_event_type_code             VARCHAR2(30);
1626 l_line_definition_code        VARCHAR2(30);
1627 l_line_definition_owner_code  VARCHAR2(1);
1628 --
1629 -- adr variables
1630 l_segment                     VARCHAR2(30);
1631 l_ccid                        NUMBER;
1632 l_adr_transaction_coa_id      NUMBER;
1633 l_adr_accounting_coa_id       NUMBER;
1634 l_adr_flexfield_segment_code  VARCHAR2(30);
1635 l_adr_flex_value_set_id       NUMBER;
1636 l_adr_value_type_code         VARCHAR2(30);
1637 l_adr_value_combination_id    NUMBER;
1638 l_adr_value_segment_code      VARCHAR2(30);
1639 
1640 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
1641 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
1642 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
1643 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
1644 
1645 -- 4262811 Variables ------------------------------------------------------------------------------------------
1646 l_entered_amt_idx             NUMBER;
1647 l_accted_amt_idx              NUMBER;
1648 l_acc_rev_flag                VARCHAR2(1);
1649 l_accrual_line_num            NUMBER;
1650 l_tmp_amt                     NUMBER;
1651 l_acc_rev_natural_side_code   VARCHAR2(1);
1655 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
1652 
1653 l_num_entries                 NUMBER;
1654 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
1656 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
1657 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
1658 l_recog_line_1                NUMBER;
1659 l_recog_line_2                NUMBER;
1660 
1661 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
1662 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
1663 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
1664 
1665 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
1666 
1667 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
1668 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
1669 
1670 ---------------------------------------------------------------------------------------------------------------
1671 
1672 
1673 --
1674 -- bulk performance
1675 --
1676 l_balance_type_code           VARCHAR2(1);
1677 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
1678 l_log_module                  VARCHAR2(240);
1679 
1680 --
1681 -- Upgrade strategy
1682 --
1683 l_actual_upg_option           VARCHAR2(1);
1684 l_enc_upg_option           VARCHAR2(1);
1685 
1686 --
1687 BEGIN
1688 --
1689 IF g_log_enabled THEN
1690       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_6';
1691 END IF;
1692 --
1693 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1694 
1695       trace
1696          (p_msg      => 'BEGIN of AcctLineType_6'
1697          ,p_level    => C_LEVEL_PROCEDURE
1698          ,p_module   => l_log_module);
1699 
1700 END IF;
1701 --
1702 l_component_type             := 'AMB_JLT';
1703 l_component_code             := 'CC_CONTRACT_CMT_PA_CR';
1704 l_component_type_code        := 'S';
1705 l_component_appl_id          :=  8407;
1706 l_amb_context_code           := 'DEFAULT';
1707 l_entity_code                := 'CC_CONTRACTS';
1708 l_event_class_code           := 'CC_CONTRACT_CMT';
1709 l_event_type_code            := 'CC_CONTRACT_CMT_ALL';
1710 l_line_definition_owner_code := 'S';
1711 l_line_definition_code       := 'CC_CONTRACT_CMT_CMN';
1712 --
1713 l_balance_type_code          := 'E';
1714 l_segment                     := NULL;
1715 l_ccid                        := NULL;
1716 l_adr_transaction_coa_id      := NULL;
1717 l_adr_accounting_coa_id       := NULL;
1718 l_adr_flexfield_segment_code  := NULL;
1719 l_adr_flex_value_set_id       := NULL;
1720 l_adr_value_type_code         := NULL;
1721 l_adr_value_combination_id    := NULL;
1722 l_adr_value_segment_code      := NULL;
1723 
1724 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
1725 l_bflow_class_code           := '';    -- 4219869 Business Flow
1726 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
1727 l_budgetary_control_flag     := 'Y';
1728 
1729 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
1730 l_bflow_applied_to_amt       := NULL; -- 5132302
1731 l_entered_amt_idx            := NULL;          -- 4262811
1732 l_accted_amt_idx             := NULL;          -- 4262811
1733 l_acc_rev_flag               := NULL;          -- 4262811
1734 l_accrual_line_num           := NULL;          -- 4262811
1735 l_tmp_amt                    := NULL;          -- 4262811
1736 --
1737  
1738 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
1739     l_balance_type_code <> 'B' THEN
1740 IF p_source_6 IS NOT NULL AND 
1741 NVL(p_source_7,'
1742 ') =  'Y'
1743  THEN 
1744 
1745    --
1746    XLA_AE_LINES_PKG.SetNewLine;
1747 
1748    p_balance_type_code          := l_balance_type_code;
1749    -- set the flag so later we will know whether the gain loss line needs to be created
1750    
1751    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
1752      p_actual_flag :='A';
1753    END IF;
1754 
1755    --
1756    -- bulk performance
1757    --
1758    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
1759                                       p_header_num   => 0); -- 4262811
1760    --
1761    -- set accounting line options
1762    --
1763    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
1764            p_natural_side_code          => 'C'
1765          , p_gain_or_loss_flag          => 'N'
1766          , p_gl_transfer_mode_code      => 'D'
1767          , p_acct_entry_type_code       => 'E'
1768          , p_switch_side_flag           => 'N'
1769          , p_merge_duplicate_code       => 'N'
1770          );
1771    --
1772    l_acc_rev_natural_side_code := 'D';  -- 4262811
1773    -- 
1774    --
1775    -- set accounting line type info
1776    --
1777    xla_ae_lines_pkg.SetAcctLineType
1778       (p_component_type             => l_component_type
1779       ,p_event_type_code            => l_event_type_code
1780       ,p_line_definition_owner_code => l_line_definition_owner_code
1781       ,p_line_definition_code       => l_line_definition_code
1782       ,p_accounting_line_code       => l_component_code
1783       ,p_accounting_line_type_code  => l_component_type_code
1784       ,p_accounting_line_appl_id    => l_component_appl_id
1788    --
1785       ,p_amb_context_code           => l_amb_context_code
1786       ,p_entity_code                => l_entity_code
1787       ,p_event_class_code           => l_event_class_code);
1789    -- set accounting class
1790    --
1791    xla_ae_lines_pkg.SetAcctClass(
1792            p_accounting_class_code  => 'PURCHASE_ORDER'
1793          , p_ae_header_id           => l_ae_header_id
1794          );
1795 
1796    --
1797    -- set rounding class
1798    --
1799    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
1800                       'PURCHASE_ORDER';
1801 
1802    --
1803    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
1804    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
1805    --
1806    -- bulk performance
1807    --
1808    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
1809 
1810    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
1811       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
1812 
1813    -- 4955764
1814    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
1815       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
1816 
1817    -- 4458381 Public Sector Enh
1818       XLA_AE_LINES_PKG.g_rec_lines.array_encumbrance_type_id(XLA_AE_LINES_PKG.g_LineNumber) := 1061;
1819    --
1820    -- set accounting attributes for the line type
1821    --
1822    l_entered_amt_idx := 3;
1823    l_accted_amt_idx  := 5;
1824    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
1825    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
1826    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_8);
1827    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
1828    l_rec_acct_attrs.array_char_value(2)  := p_source_9;
1829    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
1830    l_rec_acct_attrs.array_num_value(3)  := p_source_10;
1831    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
1832    l_rec_acct_attrs.array_char_value(4)  := p_source_11;
1833    l_rec_acct_attrs.array_acct_attr_code(5) := 'LEDGER_AMOUNT';
1834    l_rec_acct_attrs.array_num_value(5)  := p_source_10;
1835 
1836    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
1837    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
1838 
1839    ---------------------------------------------------------------------------------------------------------------
1840    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
1841    ---------------------------------------------------------------------------------------------------------------
1842    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
1843 
1844    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
1845    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
1846 
1847    IF xla_accounting_cache_pkg.GetValueChar
1848          (p_source_code         => 'LEDGER_CATEGORY_CODE'
1849          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
1850    AND l_bflow_method_code = 'PRIOR_ENTRY'
1851 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
1852    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
1853          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
1854        )
1855    THEN
1856          xla_ae_lines_pkg.BflowUpgEntry
1857            (p_business_method_code    => l_bflow_method_code
1858            ,p_business_class_code     => l_bflow_class_code
1859            ,p_balance_type            => l_balance_type_code);
1860    ELSE
1861       NULL;
1862 -- No business flow processing for business flow method of NONE.
1863    END IF;
1864 
1865    --
1866    -- call analytical criteria
1867    --
1868    
1869    --
1870    -- call description
1871    --
1872    
1873 xla_ae_lines_pkg.SetLineDescription(
1874    p_ae_header_id => l_ae_header_id
1875   ,p_description  => Description_1 (
1876      p_application_id         => p_application_id
1877    , p_ae_header_id           => l_ae_header_id 
1878 , p_source_1 => p_source_1
1879    )
1880 );
1881 
1882 
1883    --
1884    -- call ADRs
1885    -- Bug 4922099
1886    --
1887    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
1888         (NVL(l_actual_upg_option, 'N') = 'O') OR
1889         (NVL(l_enc_upg_option, 'N') = 'O')
1890       )
1891    THEN
1892    NULL;
1893    --
1894    --
1895    
1896   l_ccid := AcctDerRule_3(
1897            p_application_id           => p_application_id
1898          , p_ae_header_id             => l_ae_header_id 
1899 , p_source_5 => p_source_5
1900          , x_transaction_coa_id       => l_adr_transaction_coa_id
1901          , x_accounting_coa_id        => l_adr_accounting_coa_id
1902          , x_value_type_code          => l_adr_value_type_code
1903          , p_side                     => 'NA'
1904    );
1905 
1909   , p_transaction_coa_id           => l_adr_transaction_coa_id
1906    xla_ae_lines_pkg.set_ccid(
1907     p_code_combination_id          => l_ccid
1908   , p_value_type_code              => l_adr_value_type_code
1910   , p_accounting_coa_id            => l_adr_accounting_coa_id
1911   , p_adr_code                     => 'CC_COMMON_ADR'
1912   , p_adr_type_code                => 'S'
1913   , p_component_type               => l_component_type
1914   , p_component_code               => l_component_code
1915   , p_component_type_code          => l_component_type_code
1916   , p_component_appl_id            => l_component_appl_id
1917   , p_amb_context_code             => l_amb_context_code
1918   , p_side                         => 'NA'
1919   );
1920 
1921 
1922    --
1923    --
1924    END IF;
1925    --
1926    -- Bug 4922099
1927    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
1928           (NVL(l_enc_upg_option, 'N') = 'O')
1929         ) AND
1930         (l_bflow_method_code = 'PRIOR_ENTRY')
1931       )
1932    THEN
1933       IF
1934       --
1935       1 = 2
1936       --
1937       THEN
1938       xla_accounting_err_pkg.build_message
1939                                     (p_appli_s_name            => 'XLA'
1940                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
1941                                     ,p_token_1                 => 'LINE_NUMBER'
1942                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
1943                                     ,p_token_2                 => 'LINE_TYPE_NAME'
1944                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
1945                                                                              l_component_type
1946                                                                             ,l_component_code
1947                                                                             ,l_component_type_code
1948                                                                             ,l_component_appl_id
1949                                                                             ,l_amb_context_code
1950                                                                             ,l_entity_code
1951                                                                             ,l_event_class_code
1952                                                                            )
1953                                     ,p_token_3                 => 'OWNER'
1954                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
1955                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
1956                                                                           ,p_lookup_code    => l_component_type_code
1957                                                                          )
1958                                     ,p_token_4                 => 'PRODUCT_NAME'
1959                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
1960                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
1961                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
1962                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
1963                                     ,p_ae_header_id            =>  NULL
1964                                        );
1965 
1966         IF (C_LEVEL_ERROR>= g_log_level) THEN
1967                  trace
1968                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
1969                       ,p_level    => C_LEVEL_ERROR
1970                       ,p_module   => l_log_module);
1971         END IF;
1972       END IF;
1973    END IF;
1974    --
1975    --
1976    ------------------------------------------------------------------------------------------------
1977    -- 4219869 Business Flow
1978    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
1979    -- Prior Entry.  Currently, the following code is always generated.
1980    ------------------------------------------------------------------------------------------------
1981    XLA_AE_LINES_PKG.ValidateCurrentLine;
1982 
1983    ------------------------------------------------------------------------------------
1984    -- 4219869 Business Flow
1985    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
1986    ------------------------------------------------------------------------------------
1987    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
1988 
1989    ----------------------------------------------------------------------------------
1990    -- 4219869 Business Flow
1991    -- Update journal entry status -- Need to generate this within IF <condition>
1992    ----------------------------------------------------------------------------------
1993    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
1994          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
1995          ,p_balance_type_code => l_balance_type_code
1996          );
1997 
1998    -------------------------------------------------------------------------------------------
1999    -- 4262811 - Generate the Accrual Reversal lines
2000    -------------------------------------------------------------------------------------------
2001    BEGIN
2002       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
2006       END IF;
2003                               (g_array_event(p_event_id).array_value_num('header_index'));
2004       IF l_acc_rev_flag IS NULL THEN
2005          l_acc_rev_flag := 'N';
2007    EXCEPTION
2008       WHEN OTHERS THEN
2009          l_acc_rev_flag := 'N';
2010    END;
2011    --
2012    IF (l_acc_rev_flag = 'Y') THEN
2013 
2014        -- 4645092  ------------------------------------------------------------------------------
2015        -- To allow MPA report to determine if it should generate report process
2016        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
2017        ------------------------------------------------------------------------------------------
2018 
2019        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
2020        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
2021 
2022        --
2023        -- Update the line information that should be overwritten
2024        --
2025        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
2026                                          p_header_num   => 1);
2027        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
2028 
2029        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
2030 
2031        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
2032           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
2033        END IF;
2034 
2035       --
2036       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
2037       --
2038       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
2039           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
2040       ELSE
2041           ---------------------------------------------------------------------------------------------------
2042           -- 4262811a Switch Sign
2043           ---------------------------------------------------------------------------------------------------
2044           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
2045           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
2046                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
2047           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
2048                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
2049           -- 5132302
2050           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
2051                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
2052 
2053       END IF;
2054 
2055       -- 4955764
2056       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
2057       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
2058 
2059 
2060       XLA_AE_LINES_PKG.ValidateCurrentLine;
2061       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
2062 
2063       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
2064                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
2065                ,p_balance_type_code => l_balance_type_code);
2066 
2067    END IF;
2068 
2069    -----------------------------------------------------------------------------------------
2070    -- 4262811 Multiperiod Accounting
2071    -----------------------------------------------------------------------------------------
2072      -- No MPA option is assigned.
2073 
2074 
2075 END IF;
2076 END IF;
2077 --
2078 
2079 --
2080 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2081    trace
2082       (p_msg      => 'END of AcctLineType_6'
2083       ,p_level    => C_LEVEL_PROCEDURE
2084       ,p_module   => l_log_module);
2085 END IF;
2086 --
2087 EXCEPTION
2088   WHEN xla_exceptions_pkg.application_exception THEN
2089       RAISE;
2090   WHEN OTHERS THEN
2091        xla_exceptions_pkg.raise_message
2092            (p_location => 'XLA_08407_AAD_S_000013_BC_PKG.AcctLineType_6');
2093 END AcctLineType_6;
2094 --
2095 
2096 ---------------------------------------
2097 --
2098 -- PRIVATE FUNCTION
2099 --         AcctLineType_7
2100 --
2101 ---------------------------------------
2102 PROCEDURE AcctLineType_7 (
2103   p_application_id        IN NUMBER
2104  ,p_event_id              IN NUMBER
2105  ,p_calculate_acctd_flag  IN VARCHAR2
2106  ,p_calculate_g_l_flag    IN VARCHAR2
2107  ,p_actual_flag           IN OUT VARCHAR2
2108  ,p_balance_type_code     OUT VARCHAR2
2109  ,p_gain_or_loss_ref      OUT VARCHAR2
2110  
2111 --TRANSACTION DESCRIPTION
2112  , p_source_1            IN VARCHAR2
2113 --CODE COMBINATION ID
2114  , p_source_5            IN NUMBER
2115 --PROJECT LINE
2116  , p_source_7            IN VARCHAR2
2117 --CC ACCT LINE ID
2118  , p_source_8            IN NUMBER
2119 --DOCUMENT TYPE
2120  , p_source_9            IN VARCHAR2
2121 --CC FUNC AMT
2122  , p_source_10            IN NUMBER
2123 --CURRENCY CODE
2124  , p_source_11            IN VARCHAR2
2125 --CC FUNC DR AMT
2126  , p_source_12            IN NUMBER
2127 )
2131 l_component_code              VARCHAR2(30);
2128 IS
2129 
2130 l_component_type              VARCHAR2(80);
2132 l_component_type_code         VARCHAR2(1);
2133 l_component_appl_id           INTEGER;
2134 l_amb_context_code            VARCHAR2(30);
2135 l_entity_code                 VARCHAR2(30);
2136 l_event_class_code            VARCHAR2(30);
2137 l_ae_header_id                NUMBER;
2138 l_event_type_code             VARCHAR2(30);
2139 l_line_definition_code        VARCHAR2(30);
2140 l_line_definition_owner_code  VARCHAR2(1);
2141 --
2142 -- adr variables
2143 l_segment                     VARCHAR2(30);
2144 l_ccid                        NUMBER;
2145 l_adr_transaction_coa_id      NUMBER;
2146 l_adr_accounting_coa_id       NUMBER;
2147 l_adr_flexfield_segment_code  VARCHAR2(30);
2148 l_adr_flex_value_set_id       NUMBER;
2149 l_adr_value_type_code         VARCHAR2(30);
2150 l_adr_value_combination_id    NUMBER;
2151 l_adr_value_segment_code      VARCHAR2(30);
2152 
2153 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
2154 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
2155 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
2156 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
2157 
2158 -- 4262811 Variables ------------------------------------------------------------------------------------------
2159 l_entered_amt_idx             NUMBER;
2160 l_accted_amt_idx              NUMBER;
2161 l_acc_rev_flag                VARCHAR2(1);
2162 l_accrual_line_num            NUMBER;
2163 l_tmp_amt                     NUMBER;
2164 l_acc_rev_natural_side_code   VARCHAR2(1);
2165 
2166 l_num_entries                 NUMBER;
2167 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
2168 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
2169 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
2170 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
2171 l_recog_line_1                NUMBER;
2172 l_recog_line_2                NUMBER;
2173 
2174 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
2175 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
2176 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
2177 
2178 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
2179 
2180 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
2181 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
2182 
2183 ---------------------------------------------------------------------------------------------------------------
2184 
2185 
2186 --
2187 -- bulk performance
2188 --
2189 l_balance_type_code           VARCHAR2(1);
2190 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
2191 l_log_module                  VARCHAR2(240);
2192 
2193 --
2194 -- Upgrade strategy
2195 --
2196 l_actual_upg_option           VARCHAR2(1);
2197 l_enc_upg_option           VARCHAR2(1);
2198 
2199 --
2200 BEGIN
2201 --
2202 IF g_log_enabled THEN
2203       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_7';
2204 END IF;
2205 --
2206 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2207 
2208       trace
2209          (p_msg      => 'BEGIN of AcctLineType_7'
2210          ,p_level    => C_LEVEL_PROCEDURE
2211          ,p_module   => l_log_module);
2212 
2213 END IF;
2214 --
2215 l_component_type             := 'AMB_JLT';
2216 l_component_code             := 'CC_CONTRACT_CMT_PA_DR';
2217 l_component_type_code        := 'S';
2218 l_component_appl_id          :=  8407;
2219 l_amb_context_code           := 'DEFAULT';
2220 l_entity_code                := 'CC_CONTRACTS';
2221 l_event_class_code           := 'CC_CONTRACT_CMT';
2222 l_event_type_code            := 'CC_CONTRACT_CMT_ALL';
2223 l_line_definition_owner_code := 'S';
2224 l_line_definition_code       := 'CC_CONTRACT_CMT_CMN';
2225 --
2226 l_balance_type_code          := 'E';
2227 l_segment                     := NULL;
2228 l_ccid                        := NULL;
2229 l_adr_transaction_coa_id      := NULL;
2230 l_adr_accounting_coa_id       := NULL;
2231 l_adr_flexfield_segment_code  := NULL;
2232 l_adr_flex_value_set_id       := NULL;
2233 l_adr_value_type_code         := NULL;
2234 l_adr_value_combination_id    := NULL;
2235 l_adr_value_segment_code      := NULL;
2236 
2237 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
2238 l_bflow_class_code           := '';    -- 4219869 Business Flow
2239 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
2240 l_budgetary_control_flag     := 'Y';
2241 
2242 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
2243 l_bflow_applied_to_amt       := NULL; -- 5132302
2244 l_entered_amt_idx            := NULL;          -- 4262811
2245 l_accted_amt_idx             := NULL;          -- 4262811
2246 l_acc_rev_flag               := NULL;          -- 4262811
2247 l_accrual_line_num           := NULL;          -- 4262811
2248 l_tmp_amt                    := NULL;          -- 4262811
2249 --
2250  
2251 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
2252     l_balance_type_code <> 'B' THEN
2256  THEN 
2253 IF p_source_12 IS NOT NULL AND 
2254 NVL(p_source_7,'
2255 ') =  'Y'
2257 
2258    --
2259    XLA_AE_LINES_PKG.SetNewLine;
2260 
2261    p_balance_type_code          := l_balance_type_code;
2262    -- set the flag so later we will know whether the gain loss line needs to be created
2263    
2264    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
2265      p_actual_flag :='A';
2266    END IF;
2267 
2268    --
2269    -- bulk performance
2270    --
2271    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
2272                                       p_header_num   => 0); -- 4262811
2273    --
2274    -- set accounting line options
2275    --
2276    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
2277            p_natural_side_code          => 'D'
2278          , p_gain_or_loss_flag          => 'N'
2279          , p_gl_transfer_mode_code      => 'D'
2280          , p_acct_entry_type_code       => 'E'
2281          , p_switch_side_flag           => 'N'
2282          , p_merge_duplicate_code       => 'N'
2283          );
2284    --
2285    l_acc_rev_natural_side_code := 'C';  -- 4262811
2286    -- 
2287    --
2288    -- set accounting line type info
2289    --
2290    xla_ae_lines_pkg.SetAcctLineType
2291       (p_component_type             => l_component_type
2292       ,p_event_type_code            => l_event_type_code
2293       ,p_line_definition_owner_code => l_line_definition_owner_code
2294       ,p_line_definition_code       => l_line_definition_code
2295       ,p_accounting_line_code       => l_component_code
2296       ,p_accounting_line_type_code  => l_component_type_code
2297       ,p_accounting_line_appl_id    => l_component_appl_id
2298       ,p_amb_context_code           => l_amb_context_code
2299       ,p_entity_code                => l_entity_code
2300       ,p_event_class_code           => l_event_class_code);
2301    --
2302    -- set accounting class
2303    --
2304    xla_ae_lines_pkg.SetAcctClass(
2305            p_accounting_class_code  => 'PURCHASE_ORDER'
2306          , p_ae_header_id           => l_ae_header_id
2307          );
2308 
2309    --
2310    -- set rounding class
2311    --
2312    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
2313                       'PURCHASE_ORDER';
2314 
2315    --
2316    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
2317    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
2318    --
2319    -- bulk performance
2320    --
2321    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
2322 
2323    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
2324       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
2325 
2326    -- 4955764
2327    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
2328       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
2329 
2330    -- 4458381 Public Sector Enh
2331       XLA_AE_LINES_PKG.g_rec_lines.array_encumbrance_type_id(XLA_AE_LINES_PKG.g_LineNumber) := 1061;
2332    --
2333    -- set accounting attributes for the line type
2334    --
2335    l_entered_amt_idx := 3;
2336    l_accted_amt_idx  := 5;
2337    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
2338    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
2339    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_8);
2340    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
2341    l_rec_acct_attrs.array_char_value(2)  := p_source_9;
2342    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
2343    l_rec_acct_attrs.array_num_value(3)  := p_source_10;
2344    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
2345    l_rec_acct_attrs.array_char_value(4)  := p_source_11;
2346    l_rec_acct_attrs.array_acct_attr_code(5) := 'LEDGER_AMOUNT';
2347    l_rec_acct_attrs.array_num_value(5)  := p_source_10;
2348 
2349    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
2350    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
2351 
2352    ---------------------------------------------------------------------------------------------------------------
2353    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
2354    ---------------------------------------------------------------------------------------------------------------
2355    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
2356 
2357    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
2358    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
2359 
2360    IF xla_accounting_cache_pkg.GetValueChar
2361          (p_source_code         => 'LEDGER_CATEGORY_CODE'
2362          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
2363    AND l_bflow_method_code = 'PRIOR_ENTRY'
2364 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
2365    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
2369          xla_ae_lines_pkg.BflowUpgEntry
2366          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
2367        )
2368    THEN
2370            (p_business_method_code    => l_bflow_method_code
2371            ,p_business_class_code     => l_bflow_class_code
2372            ,p_balance_type            => l_balance_type_code);
2373    ELSE
2374       NULL;
2375 -- No business flow processing for business flow method of NONE.
2376    END IF;
2377 
2378    --
2379    -- call analytical criteria
2380    --
2381    
2382    --
2383    -- call description
2384    --
2385    
2386 xla_ae_lines_pkg.SetLineDescription(
2387    p_ae_header_id => l_ae_header_id
2388   ,p_description  => Description_1 (
2389      p_application_id         => p_application_id
2390    , p_ae_header_id           => l_ae_header_id 
2391 , p_source_1 => p_source_1
2392    )
2393 );
2394 
2395 
2396    --
2397    -- call ADRs
2398    -- Bug 4922099
2399    --
2400    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
2401         (NVL(l_actual_upg_option, 'N') = 'O') OR
2402         (NVL(l_enc_upg_option, 'N') = 'O')
2403       )
2404    THEN
2405    NULL;
2406    --
2407    --
2408    
2409   l_ccid := AcctDerRule_3(
2410            p_application_id           => p_application_id
2411          , p_ae_header_id             => l_ae_header_id 
2412 , p_source_5 => p_source_5
2413          , x_transaction_coa_id       => l_adr_transaction_coa_id
2414          , x_accounting_coa_id        => l_adr_accounting_coa_id
2415          , x_value_type_code          => l_adr_value_type_code
2416          , p_side                     => 'NA'
2417    );
2418 
2419    xla_ae_lines_pkg.set_ccid(
2420     p_code_combination_id          => l_ccid
2421   , p_value_type_code              => l_adr_value_type_code
2422   , p_transaction_coa_id           => l_adr_transaction_coa_id
2423   , p_accounting_coa_id            => l_adr_accounting_coa_id
2424   , p_adr_code                     => 'CC_COMMON_ADR'
2425   , p_adr_type_code                => 'S'
2426   , p_component_type               => l_component_type
2427   , p_component_code               => l_component_code
2428   , p_component_type_code          => l_component_type_code
2429   , p_component_appl_id            => l_component_appl_id
2430   , p_amb_context_code             => l_amb_context_code
2431   , p_side                         => 'NA'
2432   );
2433 
2434 
2435    --
2436    --
2437    END IF;
2438    --
2439    -- Bug 4922099
2440    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
2441           (NVL(l_enc_upg_option, 'N') = 'O')
2442         ) AND
2443         (l_bflow_method_code = 'PRIOR_ENTRY')
2444       )
2445    THEN
2446       IF
2447       --
2448       1 = 2
2449       --
2450       THEN
2451       xla_accounting_err_pkg.build_message
2452                                     (p_appli_s_name            => 'XLA'
2453                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
2454                                     ,p_token_1                 => 'LINE_NUMBER'
2455                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
2456                                     ,p_token_2                 => 'LINE_TYPE_NAME'
2457                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
2458                                                                              l_component_type
2459                                                                             ,l_component_code
2460                                                                             ,l_component_type_code
2461                                                                             ,l_component_appl_id
2462                                                                             ,l_amb_context_code
2463                                                                             ,l_entity_code
2464                                                                             ,l_event_class_code
2465                                                                            )
2466                                     ,p_token_3                 => 'OWNER'
2467                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
2468                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
2469                                                                           ,p_lookup_code    => l_component_type_code
2470                                                                          )
2471                                     ,p_token_4                 => 'PRODUCT_NAME'
2472                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
2473                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
2474                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
2475                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
2476                                     ,p_ae_header_id            =>  NULL
2477                                        );
2478 
2479         IF (C_LEVEL_ERROR>= g_log_level) THEN
2480                  trace
2481                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
2482                       ,p_level    => C_LEVEL_ERROR
2486    END IF;
2483                       ,p_module   => l_log_module);
2484         END IF;
2485       END IF;
2487    --
2488    --
2489    ------------------------------------------------------------------------------------------------
2490    -- 4219869 Business Flow
2491    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
2492    -- Prior Entry.  Currently, the following code is always generated.
2493    ------------------------------------------------------------------------------------------------
2494    XLA_AE_LINES_PKG.ValidateCurrentLine;
2495 
2496    ------------------------------------------------------------------------------------
2497    -- 4219869 Business Flow
2498    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
2499    ------------------------------------------------------------------------------------
2500    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
2501 
2502    ----------------------------------------------------------------------------------
2503    -- 4219869 Business Flow
2504    -- Update journal entry status -- Need to generate this within IF <condition>
2505    ----------------------------------------------------------------------------------
2506    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
2507          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
2508          ,p_balance_type_code => l_balance_type_code
2509          );
2510 
2511    -------------------------------------------------------------------------------------------
2512    -- 4262811 - Generate the Accrual Reversal lines
2513    -------------------------------------------------------------------------------------------
2514    BEGIN
2515       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
2516                               (g_array_event(p_event_id).array_value_num('header_index'));
2517       IF l_acc_rev_flag IS NULL THEN
2518          l_acc_rev_flag := 'N';
2519       END IF;
2520    EXCEPTION
2521       WHEN OTHERS THEN
2522          l_acc_rev_flag := 'N';
2523    END;
2524    --
2525    IF (l_acc_rev_flag = 'Y') THEN
2526 
2527        -- 4645092  ------------------------------------------------------------------------------
2528        -- To allow MPA report to determine if it should generate report process
2529        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
2530        ------------------------------------------------------------------------------------------
2531 
2532        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
2533        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
2534 
2535        --
2536        -- Update the line information that should be overwritten
2537        --
2538        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
2539                                          p_header_num   => 1);
2540        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
2541 
2542        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
2543 
2544        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
2545           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
2546        END IF;
2547 
2548       --
2549       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
2550       --
2551       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
2552           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
2553       ELSE
2554           ---------------------------------------------------------------------------------------------------
2555           -- 4262811a Switch Sign
2556           ---------------------------------------------------------------------------------------------------
2557           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
2558           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
2559                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
2560           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
2561                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
2562           -- 5132302
2563           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
2564                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
2565 
2566       END IF;
2567 
2568       -- 4955764
2569       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
2570       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
2571 
2572 
2573       XLA_AE_LINES_PKG.ValidateCurrentLine;
2574       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
2575 
2576       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
2577                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
2578                ,p_balance_type_code => l_balance_type_code);
2579 
2580    END IF;
2581 
2582    -----------------------------------------------------------------------------------------
2583    -- 4262811 Multiperiod Accounting
2587 
2584    -----------------------------------------------------------------------------------------
2585      -- No MPA option is assigned.
2586 
2588 END IF;
2589 END IF;
2590 --
2591 
2592 --
2593 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2594    trace
2595       (p_msg      => 'END of AcctLineType_7'
2596       ,p_level    => C_LEVEL_PROCEDURE
2597       ,p_module   => l_log_module);
2598 END IF;
2599 --
2600 EXCEPTION
2601   WHEN xla_exceptions_pkg.application_exception THEN
2602       RAISE;
2603   WHEN OTHERS THEN
2604        xla_exceptions_pkg.raise_message
2605            (p_location => 'XLA_08407_AAD_S_000013_BC_PKG.AcctLineType_7');
2606 END AcctLineType_7;
2607 --
2608 
2609 ---------------------------------------
2610 --
2611 -- PRIVATE FUNCTION
2612 --         AcctLineType_8
2613 --
2614 ---------------------------------------
2615 PROCEDURE AcctLineType_8 (
2616   p_application_id        IN NUMBER
2617  ,p_event_id              IN NUMBER
2618  ,p_calculate_acctd_flag  IN VARCHAR2
2619  ,p_calculate_g_l_flag    IN VARCHAR2
2620  ,p_actual_flag           IN OUT VARCHAR2
2621  ,p_balance_type_code     OUT VARCHAR2
2622  ,p_gain_or_loss_ref      OUT VARCHAR2
2623  
2624 --TRANSACTION DESCRIPTION
2625  , p_source_1            IN VARCHAR2
2626 --CODE COMBINATION ID
2627  , p_source_5            IN NUMBER
2628 --CC FUNC CR AMT
2629  , p_source_6            IN NUMBER
2630 --PROJECT LINE
2631  , p_source_7            IN VARCHAR2
2632 --CC ACCT LINE ID
2633  , p_source_8            IN NUMBER
2634 --DOCUMENT TYPE
2635  , p_source_9            IN VARCHAR2
2636 --CC FUNC AMT
2637  , p_source_10            IN NUMBER
2638 --CURRENCY CODE
2639  , p_source_11            IN VARCHAR2
2640 )
2641 IS
2642 
2643 l_component_type              VARCHAR2(80);
2644 l_component_code              VARCHAR2(30);
2645 l_component_type_code         VARCHAR2(1);
2646 l_component_appl_id           INTEGER;
2647 l_amb_context_code            VARCHAR2(30);
2648 l_entity_code                 VARCHAR2(30);
2649 l_event_class_code            VARCHAR2(30);
2650 l_ae_header_id                NUMBER;
2651 l_event_type_code             VARCHAR2(30);
2652 l_line_definition_code        VARCHAR2(30);
2653 l_line_definition_owner_code  VARCHAR2(1);
2654 --
2655 -- adr variables
2656 l_segment                     VARCHAR2(30);
2657 l_ccid                        NUMBER;
2658 l_adr_transaction_coa_id      NUMBER;
2659 l_adr_accounting_coa_id       NUMBER;
2660 l_adr_flexfield_segment_code  VARCHAR2(30);
2661 l_adr_flex_value_set_id       NUMBER;
2662 l_adr_value_type_code         VARCHAR2(30);
2663 l_adr_value_combination_id    NUMBER;
2664 l_adr_value_segment_code      VARCHAR2(30);
2665 
2666 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
2667 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
2668 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
2669 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
2670 
2671 -- 4262811 Variables ------------------------------------------------------------------------------------------
2672 l_entered_amt_idx             NUMBER;
2673 l_accted_amt_idx              NUMBER;
2674 l_acc_rev_flag                VARCHAR2(1);
2675 l_accrual_line_num            NUMBER;
2676 l_tmp_amt                     NUMBER;
2677 l_acc_rev_natural_side_code   VARCHAR2(1);
2678 
2679 l_num_entries                 NUMBER;
2680 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
2681 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
2682 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
2683 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
2684 l_recog_line_1                NUMBER;
2685 l_recog_line_2                NUMBER;
2686 
2687 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
2688 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
2689 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
2690 
2691 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
2692 
2693 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
2694 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
2695 
2696 ---------------------------------------------------------------------------------------------------------------
2697 
2698 
2699 --
2700 -- bulk performance
2701 --
2702 l_balance_type_code           VARCHAR2(1);
2703 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
2704 l_log_module                  VARCHAR2(240);
2705 
2706 --
2707 -- Upgrade strategy
2708 --
2709 l_actual_upg_option           VARCHAR2(1);
2710 l_enc_upg_option           VARCHAR2(1);
2711 
2712 --
2713 BEGIN
2714 --
2715 IF g_log_enabled THEN
2716       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_8';
2717 END IF;
2718 --
2719 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2720 
2721       trace
2722          (p_msg      => 'BEGIN of AcctLineType_8'
2723          ,p_level    => C_LEVEL_PROCEDURE
2724          ,p_module   => l_log_module);
2725 
2726 END IF;
2727 --
2728 l_component_type             := 'AMB_JLT';
2732 l_amb_context_code           := 'DEFAULT';
2729 l_component_code             := 'CC_CONTRACT_PRO_CR';
2730 l_component_type_code        := 'S';
2731 l_component_appl_id          :=  8407;
2733 l_entity_code                := 'CC_CONTRACTS';
2734 l_event_class_code           := 'CC_CONTRACT_PRO';
2735 l_event_type_code            := 'CC_CONTRACT_PRO_ALL';
2736 l_line_definition_owner_code := 'S';
2737 l_line_definition_code       := 'CC_CONTRACT_PRO_CMN';
2738 --
2739 l_balance_type_code          := 'E';
2740 l_segment                     := NULL;
2741 l_ccid                        := NULL;
2742 l_adr_transaction_coa_id      := NULL;
2743 l_adr_accounting_coa_id       := NULL;
2744 l_adr_flexfield_segment_code  := NULL;
2745 l_adr_flex_value_set_id       := NULL;
2746 l_adr_value_type_code         := NULL;
2747 l_adr_value_combination_id    := NULL;
2748 l_adr_value_segment_code      := NULL;
2749 
2750 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
2751 l_bflow_class_code           := '';    -- 4219869 Business Flow
2752 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
2753 l_budgetary_control_flag     := 'Y';
2754 
2755 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
2756 l_bflow_applied_to_amt       := NULL; -- 5132302
2757 l_entered_amt_idx            := NULL;          -- 4262811
2758 l_accted_amt_idx             := NULL;          -- 4262811
2759 l_acc_rev_flag               := NULL;          -- 4262811
2760 l_accrual_line_num           := NULL;          -- 4262811
2761 l_tmp_amt                    := NULL;          -- 4262811
2762 --
2763  
2764 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
2765     l_balance_type_code <> 'B' THEN
2766 IF p_source_6 IS NOT NULL AND 
2767 NVL(p_source_7,'
2768 ') <>  'Y'
2769  THEN 
2770 
2771    --
2772    XLA_AE_LINES_PKG.SetNewLine;
2773 
2774    p_balance_type_code          := l_balance_type_code;
2775    -- set the flag so later we will know whether the gain loss line needs to be created
2776    
2777    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
2778      p_actual_flag :='A';
2779    END IF;
2780 
2781    --
2782    -- bulk performance
2783    --
2784    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
2785                                       p_header_num   => 0); -- 4262811
2786    --
2787    -- set accounting line options
2788    --
2789    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
2790            p_natural_side_code          => 'C'
2791          , p_gain_or_loss_flag          => 'N'
2792          , p_gl_transfer_mode_code      => 'D'
2793          , p_acct_entry_type_code       => 'E'
2794          , p_switch_side_flag           => 'N'
2795          , p_merge_duplicate_code       => 'N'
2796          );
2797    --
2798    l_acc_rev_natural_side_code := 'D';  -- 4262811
2799    -- 
2800    --
2801    -- set accounting line type info
2802    --
2803    xla_ae_lines_pkg.SetAcctLineType
2804       (p_component_type             => l_component_type
2805       ,p_event_type_code            => l_event_type_code
2806       ,p_line_definition_owner_code => l_line_definition_owner_code
2807       ,p_line_definition_code       => l_line_definition_code
2808       ,p_accounting_line_code       => l_component_code
2809       ,p_accounting_line_type_code  => l_component_type_code
2810       ,p_accounting_line_appl_id    => l_component_appl_id
2811       ,p_amb_context_code           => l_amb_context_code
2812       ,p_entity_code                => l_entity_code
2813       ,p_event_class_code           => l_event_class_code);
2814    --
2815    -- set accounting class
2816    --
2817    xla_ae_lines_pkg.SetAcctClass(
2818            p_accounting_class_code  => 'REQUISITION'
2819          , p_ae_header_id           => l_ae_header_id
2820          );
2821 
2822    --
2823    -- set rounding class
2824    --
2825    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
2826                       'REQUISITION';
2827 
2828    --
2829    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
2830    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
2831    --
2832    -- bulk performance
2833    --
2834    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
2835 
2836    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
2837       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
2838 
2839    -- 4955764
2840    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
2841       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
2842 
2843    -- 4458381 Public Sector Enh
2844       XLA_AE_LINES_PKG.g_rec_lines.array_encumbrance_type_id(XLA_AE_LINES_PKG.g_LineNumber) := 1000;
2845    --
2846    -- set accounting attributes for the line type
2847    --
2848    l_entered_amt_idx := 3;
2849    l_accted_amt_idx  := 5;
2850    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
2851    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
2855    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
2852    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_8);
2853    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
2854    l_rec_acct_attrs.array_char_value(2)  := p_source_9;
2856    l_rec_acct_attrs.array_num_value(3)  := p_source_10;
2857    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
2858    l_rec_acct_attrs.array_char_value(4)  := p_source_11;
2859    l_rec_acct_attrs.array_acct_attr_code(5) := 'LEDGER_AMOUNT';
2860    l_rec_acct_attrs.array_num_value(5)  := p_source_10;
2861 
2862    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
2863    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
2864 
2865    ---------------------------------------------------------------------------------------------------------------
2866    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
2867    ---------------------------------------------------------------------------------------------------------------
2868    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
2869 
2870    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
2871    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
2872 
2873    IF xla_accounting_cache_pkg.GetValueChar
2874          (p_source_code         => 'LEDGER_CATEGORY_CODE'
2875          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
2876    AND l_bflow_method_code = 'PRIOR_ENTRY'
2877 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
2878    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
2879          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
2880        )
2881    THEN
2882          xla_ae_lines_pkg.BflowUpgEntry
2883            (p_business_method_code    => l_bflow_method_code
2884            ,p_business_class_code     => l_bflow_class_code
2885            ,p_balance_type            => l_balance_type_code);
2886    ELSE
2887       NULL;
2888 -- No business flow processing for business flow method of NONE.
2889    END IF;
2890 
2891    --
2892    -- call analytical criteria
2893    --
2894    
2895    --
2896    -- call description
2897    --
2898    
2899 xla_ae_lines_pkg.SetLineDescription(
2900    p_ae_header_id => l_ae_header_id
2901   ,p_description  => Description_1 (
2902      p_application_id         => p_application_id
2903    , p_ae_header_id           => l_ae_header_id 
2904 , p_source_1 => p_source_1
2905    )
2906 );
2907 
2908 
2909    --
2910    -- call ADRs
2911    -- Bug 4922099
2912    --
2913    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
2914         (NVL(l_actual_upg_option, 'N') = 'O') OR
2915         (NVL(l_enc_upg_option, 'N') = 'O')
2916       )
2917    THEN
2918    NULL;
2919    --
2920    --
2921    
2922   l_ccid := AcctDerRule_3(
2923            p_application_id           => p_application_id
2924          , p_ae_header_id             => l_ae_header_id 
2925 , p_source_5 => p_source_5
2926          , x_transaction_coa_id       => l_adr_transaction_coa_id
2927          , x_accounting_coa_id        => l_adr_accounting_coa_id
2928          , x_value_type_code          => l_adr_value_type_code
2929          , p_side                     => 'NA'
2930    );
2931 
2932    xla_ae_lines_pkg.set_ccid(
2933     p_code_combination_id          => l_ccid
2934   , p_value_type_code              => l_adr_value_type_code
2935   , p_transaction_coa_id           => l_adr_transaction_coa_id
2936   , p_accounting_coa_id            => l_adr_accounting_coa_id
2937   , p_adr_code                     => 'CC_COMMON_ADR'
2938   , p_adr_type_code                => 'S'
2939   , p_component_type               => l_component_type
2940   , p_component_code               => l_component_code
2941   , p_component_type_code          => l_component_type_code
2942   , p_component_appl_id            => l_component_appl_id
2943   , p_amb_context_code             => l_amb_context_code
2944   , p_side                         => 'NA'
2945   );
2946 
2947 
2948    --
2949    --
2950    END IF;
2951    --
2952    -- Bug 4922099
2953    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
2954           (NVL(l_enc_upg_option, 'N') = 'O')
2955         ) AND
2956         (l_bflow_method_code = 'PRIOR_ENTRY')
2957       )
2958    THEN
2959       IF
2960       --
2961       1 = 2
2962       --
2963       THEN
2964       xla_accounting_err_pkg.build_message
2965                                     (p_appli_s_name            => 'XLA'
2966                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
2967                                     ,p_token_1                 => 'LINE_NUMBER'
2968                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
2969                                     ,p_token_2                 => 'LINE_TYPE_NAME'
2970                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
2971                                                                              l_component_type
2972                                                                             ,l_component_code
2973                                                                             ,l_component_type_code
2977                                                                             ,l_event_class_code
2974                                                                             ,l_component_appl_id
2975                                                                             ,l_amb_context_code
2976                                                                             ,l_entity_code
2978                                                                            )
2979                                     ,p_token_3                 => 'OWNER'
2980                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
2981                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
2982                                                                           ,p_lookup_code    => l_component_type_code
2983                                                                          )
2984                                     ,p_token_4                 => 'PRODUCT_NAME'
2985                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
2986                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
2987                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
2988                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
2989                                     ,p_ae_header_id            =>  NULL
2990                                        );
2991 
2992         IF (C_LEVEL_ERROR>= g_log_level) THEN
2993                  trace
2994                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
2995                       ,p_level    => C_LEVEL_ERROR
2996                       ,p_module   => l_log_module);
2997         END IF;
2998       END IF;
2999    END IF;
3000    --
3001    --
3002    ------------------------------------------------------------------------------------------------
3003    -- 4219869 Business Flow
3004    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
3005    -- Prior Entry.  Currently, the following code is always generated.
3006    ------------------------------------------------------------------------------------------------
3007    XLA_AE_LINES_PKG.ValidateCurrentLine;
3008 
3009    ------------------------------------------------------------------------------------
3010    -- 4219869 Business Flow
3011    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
3012    ------------------------------------------------------------------------------------
3013    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
3014 
3015    ----------------------------------------------------------------------------------
3016    -- 4219869 Business Flow
3017    -- Update journal entry status -- Need to generate this within IF <condition>
3018    ----------------------------------------------------------------------------------
3019    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
3020          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
3021          ,p_balance_type_code => l_balance_type_code
3022          );
3023 
3024    -------------------------------------------------------------------------------------------
3025    -- 4262811 - Generate the Accrual Reversal lines
3026    -------------------------------------------------------------------------------------------
3027    BEGIN
3028       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
3029                               (g_array_event(p_event_id).array_value_num('header_index'));
3030       IF l_acc_rev_flag IS NULL THEN
3031          l_acc_rev_flag := 'N';
3032       END IF;
3033    EXCEPTION
3034       WHEN OTHERS THEN
3035          l_acc_rev_flag := 'N';
3036    END;
3037    --
3038    IF (l_acc_rev_flag = 'Y') THEN
3039 
3040        -- 4645092  ------------------------------------------------------------------------------
3041        -- To allow MPA report to determine if it should generate report process
3042        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
3043        ------------------------------------------------------------------------------------------
3044 
3045        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
3046        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
3047 
3048        --
3049        -- Update the line information that should be overwritten
3050        --
3051        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
3052                                          p_header_num   => 1);
3053        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
3054 
3055        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
3056 
3057        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
3058           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
3059        END IF;
3060 
3061       --
3062       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
3063       --
3064       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
3065           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
3066       ELSE
3067           ---------------------------------------------------------------------------------------------------
3071           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
3068           -- 4262811a Switch Sign
3069           ---------------------------------------------------------------------------------------------------
3070           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
3072                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
3073           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
3074                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
3075           -- 5132302
3076           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
3077                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
3078 
3079       END IF;
3080 
3081       -- 4955764
3082       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
3083       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
3084 
3085 
3086       XLA_AE_LINES_PKG.ValidateCurrentLine;
3087       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
3088 
3089       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
3090                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
3091                ,p_balance_type_code => l_balance_type_code);
3092 
3093    END IF;
3094 
3095    -----------------------------------------------------------------------------------------
3096    -- 4262811 Multiperiod Accounting
3097    -----------------------------------------------------------------------------------------
3098      -- No MPA option is assigned.
3099 
3100 
3101 END IF;
3102 END IF;
3103 --
3104 
3105 --
3106 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3107    trace
3108       (p_msg      => 'END of AcctLineType_8'
3109       ,p_level    => C_LEVEL_PROCEDURE
3110       ,p_module   => l_log_module);
3111 END IF;
3112 --
3113 EXCEPTION
3114   WHEN xla_exceptions_pkg.application_exception THEN
3115       RAISE;
3116   WHEN OTHERS THEN
3117        xla_exceptions_pkg.raise_message
3118            (p_location => 'XLA_08407_AAD_S_000013_BC_PKG.AcctLineType_8');
3119 END AcctLineType_8;
3120 --
3121 
3122 ---------------------------------------
3123 --
3124 -- PRIVATE FUNCTION
3125 --         AcctLineType_9
3126 --
3127 ---------------------------------------
3128 PROCEDURE AcctLineType_9 (
3129   p_application_id        IN NUMBER
3130  ,p_event_id              IN NUMBER
3131  ,p_calculate_acctd_flag  IN VARCHAR2
3132  ,p_calculate_g_l_flag    IN VARCHAR2
3133  ,p_actual_flag           IN OUT VARCHAR2
3134  ,p_balance_type_code     OUT VARCHAR2
3135  ,p_gain_or_loss_ref      OUT VARCHAR2
3136  
3137 --TRANSACTION DESCRIPTION
3138  , p_source_1            IN VARCHAR2
3139 --CODE COMBINATION ID
3140  , p_source_5            IN NUMBER
3141 --PROJECT LINE
3142  , p_source_7            IN VARCHAR2
3143 --CC ACCT LINE ID
3144  , p_source_8            IN NUMBER
3145 --DOCUMENT TYPE
3146  , p_source_9            IN VARCHAR2
3147 --CC FUNC AMT
3148  , p_source_10            IN NUMBER
3149 --CURRENCY CODE
3150  , p_source_11            IN VARCHAR2
3151 --CC FUNC DR AMT
3152  , p_source_12            IN NUMBER
3153 )
3154 IS
3155 
3156 l_component_type              VARCHAR2(80);
3157 l_component_code              VARCHAR2(30);
3158 l_component_type_code         VARCHAR2(1);
3159 l_component_appl_id           INTEGER;
3160 l_amb_context_code            VARCHAR2(30);
3161 l_entity_code                 VARCHAR2(30);
3162 l_event_class_code            VARCHAR2(30);
3163 l_ae_header_id                NUMBER;
3164 l_event_type_code             VARCHAR2(30);
3165 l_line_definition_code        VARCHAR2(30);
3166 l_line_definition_owner_code  VARCHAR2(1);
3167 --
3168 -- adr variables
3169 l_segment                     VARCHAR2(30);
3170 l_ccid                        NUMBER;
3171 l_adr_transaction_coa_id      NUMBER;
3172 l_adr_accounting_coa_id       NUMBER;
3173 l_adr_flexfield_segment_code  VARCHAR2(30);
3174 l_adr_flex_value_set_id       NUMBER;
3175 l_adr_value_type_code         VARCHAR2(30);
3176 l_adr_value_combination_id    NUMBER;
3177 l_adr_value_segment_code      VARCHAR2(30);
3178 
3179 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
3180 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
3181 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
3182 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
3183 
3184 -- 4262811 Variables ------------------------------------------------------------------------------------------
3185 l_entered_amt_idx             NUMBER;
3186 l_accted_amt_idx              NUMBER;
3187 l_acc_rev_flag                VARCHAR2(1);
3188 l_accrual_line_num            NUMBER;
3189 l_tmp_amt                     NUMBER;
3190 l_acc_rev_natural_side_code   VARCHAR2(1);
3191 
3192 l_num_entries                 NUMBER;
3193 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
3194 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
3198 l_recog_line_2                NUMBER;
3195 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
3196 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
3197 l_recog_line_1                NUMBER;
3199 
3200 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
3201 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
3202 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
3203 
3204 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
3205 
3206 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
3207 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
3208 
3209 ---------------------------------------------------------------------------------------------------------------
3210 
3211 
3212 --
3213 -- bulk performance
3214 --
3215 l_balance_type_code           VARCHAR2(1);
3216 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
3217 l_log_module                  VARCHAR2(240);
3218 
3219 --
3220 -- Upgrade strategy
3221 --
3222 l_actual_upg_option           VARCHAR2(1);
3223 l_enc_upg_option           VARCHAR2(1);
3224 
3225 --
3226 BEGIN
3227 --
3228 IF g_log_enabled THEN
3229       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_9';
3230 END IF;
3231 --
3232 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3233 
3234       trace
3235          (p_msg      => 'BEGIN of AcctLineType_9'
3236          ,p_level    => C_LEVEL_PROCEDURE
3237          ,p_module   => l_log_module);
3238 
3239 END IF;
3240 --
3241 l_component_type             := 'AMB_JLT';
3242 l_component_code             := 'CC_CONTRACT_PRO_DR';
3243 l_component_type_code        := 'S';
3244 l_component_appl_id          :=  8407;
3245 l_amb_context_code           := 'DEFAULT';
3246 l_entity_code                := 'CC_CONTRACTS';
3247 l_event_class_code           := 'CC_CONTRACT_PRO';
3248 l_event_type_code            := 'CC_CONTRACT_PRO_ALL';
3249 l_line_definition_owner_code := 'S';
3250 l_line_definition_code       := 'CC_CONTRACT_PRO_CMN';
3251 --
3252 l_balance_type_code          := 'E';
3253 l_segment                     := NULL;
3254 l_ccid                        := NULL;
3255 l_adr_transaction_coa_id      := NULL;
3256 l_adr_accounting_coa_id       := NULL;
3257 l_adr_flexfield_segment_code  := NULL;
3258 l_adr_flex_value_set_id       := NULL;
3259 l_adr_value_type_code         := NULL;
3260 l_adr_value_combination_id    := NULL;
3261 l_adr_value_segment_code      := NULL;
3262 
3263 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
3264 l_bflow_class_code           := '';    -- 4219869 Business Flow
3265 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
3266 l_budgetary_control_flag     := 'Y';
3267 
3268 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
3269 l_bflow_applied_to_amt       := NULL; -- 5132302
3270 l_entered_amt_idx            := NULL;          -- 4262811
3271 l_accted_amt_idx             := NULL;          -- 4262811
3272 l_acc_rev_flag               := NULL;          -- 4262811
3273 l_accrual_line_num           := NULL;          -- 4262811
3274 l_tmp_amt                    := NULL;          -- 4262811
3275 --
3276  
3277 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
3278     l_balance_type_code <> 'B' THEN
3279 IF p_source_12 IS NOT NULL AND 
3280 NVL(p_source_7,'
3281 ') <>  'Y'
3282  THEN 
3283 
3284    --
3285    XLA_AE_LINES_PKG.SetNewLine;
3286 
3287    p_balance_type_code          := l_balance_type_code;
3288    -- set the flag so later we will know whether the gain loss line needs to be created
3289    
3290    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
3291      p_actual_flag :='A';
3292    END IF;
3293 
3294    --
3295    -- bulk performance
3296    --
3297    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
3298                                       p_header_num   => 0); -- 4262811
3299    --
3300    -- set accounting line options
3301    --
3302    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
3303            p_natural_side_code          => 'D'
3304          , p_gain_or_loss_flag          => 'N'
3305          , p_gl_transfer_mode_code      => 'D'
3306          , p_acct_entry_type_code       => 'E'
3307          , p_switch_side_flag           => 'N'
3308          , p_merge_duplicate_code       => 'N'
3309          );
3310    --
3311    l_acc_rev_natural_side_code := 'C';  -- 4262811
3312    -- 
3313    --
3314    -- set accounting line type info
3315    --
3316    xla_ae_lines_pkg.SetAcctLineType
3317       (p_component_type             => l_component_type
3318       ,p_event_type_code            => l_event_type_code
3319       ,p_line_definition_owner_code => l_line_definition_owner_code
3320       ,p_line_definition_code       => l_line_definition_code
3321       ,p_accounting_line_code       => l_component_code
3322       ,p_accounting_line_type_code  => l_component_type_code
3323       ,p_accounting_line_appl_id    => l_component_appl_id
3324       ,p_amb_context_code           => l_amb_context_code
3325       ,p_entity_code                => l_entity_code
3329    --
3326       ,p_event_class_code           => l_event_class_code);
3327    --
3328    -- set accounting class
3330    xla_ae_lines_pkg.SetAcctClass(
3331            p_accounting_class_code  => 'REQUISITION'
3332          , p_ae_header_id           => l_ae_header_id
3333          );
3334 
3335    --
3336    -- set rounding class
3337    --
3338    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
3339                       'REQUISITION';
3340 
3341    --
3342    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
3343    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
3344    --
3345    -- bulk performance
3346    --
3347    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
3348 
3349    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
3350       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
3351 
3352    -- 4955764
3353    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
3354       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
3355 
3356    -- 4458381 Public Sector Enh
3357       XLA_AE_LINES_PKG.g_rec_lines.array_encumbrance_type_id(XLA_AE_LINES_PKG.g_LineNumber) := 1000;
3358    --
3359    -- set accounting attributes for the line type
3360    --
3361    l_entered_amt_idx := 3;
3362    l_accted_amt_idx  := 5;
3363    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
3364    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
3365    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_8);
3366    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
3367    l_rec_acct_attrs.array_char_value(2)  := p_source_9;
3368    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
3369    l_rec_acct_attrs.array_num_value(3)  := p_source_10;
3370    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
3371    l_rec_acct_attrs.array_char_value(4)  := p_source_11;
3372    l_rec_acct_attrs.array_acct_attr_code(5) := 'LEDGER_AMOUNT';
3373    l_rec_acct_attrs.array_num_value(5)  := p_source_10;
3374 
3375    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
3376    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
3377 
3378    ---------------------------------------------------------------------------------------------------------------
3379    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
3380    ---------------------------------------------------------------------------------------------------------------
3381    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
3382 
3383    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
3384    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
3385 
3386    IF xla_accounting_cache_pkg.GetValueChar
3387          (p_source_code         => 'LEDGER_CATEGORY_CODE'
3388          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
3389    AND l_bflow_method_code = 'PRIOR_ENTRY'
3390 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
3391    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
3392          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
3393        )
3394    THEN
3395          xla_ae_lines_pkg.BflowUpgEntry
3396            (p_business_method_code    => l_bflow_method_code
3397            ,p_business_class_code     => l_bflow_class_code
3398            ,p_balance_type            => l_balance_type_code);
3399    ELSE
3400       NULL;
3401 -- No business flow processing for business flow method of NONE.
3402    END IF;
3403 
3404    --
3405    -- call analytical criteria
3406    --
3407    
3408    --
3409    -- call description
3410    --
3411    
3412 xla_ae_lines_pkg.SetLineDescription(
3413    p_ae_header_id => l_ae_header_id
3414   ,p_description  => Description_1 (
3415      p_application_id         => p_application_id
3416    , p_ae_header_id           => l_ae_header_id 
3417 , p_source_1 => p_source_1
3418    )
3419 );
3420 
3421 
3422    --
3423    -- call ADRs
3424    -- Bug 4922099
3425    --
3426    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
3427         (NVL(l_actual_upg_option, 'N') = 'O') OR
3428         (NVL(l_enc_upg_option, 'N') = 'O')
3429       )
3430    THEN
3431    NULL;
3432    --
3433    --
3434    
3435   l_ccid := AcctDerRule_3(
3436            p_application_id           => p_application_id
3437          , p_ae_header_id             => l_ae_header_id 
3438 , p_source_5 => p_source_5
3439          , x_transaction_coa_id       => l_adr_transaction_coa_id
3440          , x_accounting_coa_id        => l_adr_accounting_coa_id
3441          , x_value_type_code          => l_adr_value_type_code
3442          , p_side                     => 'NA'
3443    );
3444 
3445    xla_ae_lines_pkg.set_ccid(
3446     p_code_combination_id          => l_ccid
3447   , p_value_type_code              => l_adr_value_type_code
3451   , p_adr_type_code                => 'S'
3448   , p_transaction_coa_id           => l_adr_transaction_coa_id
3449   , p_accounting_coa_id            => l_adr_accounting_coa_id
3450   , p_adr_code                     => 'CC_COMMON_ADR'
3452   , p_component_type               => l_component_type
3453   , p_component_code               => l_component_code
3454   , p_component_type_code          => l_component_type_code
3455   , p_component_appl_id            => l_component_appl_id
3456   , p_amb_context_code             => l_amb_context_code
3457   , p_side                         => 'NA'
3458   );
3459 
3460 
3461    --
3462    --
3463    END IF;
3464    --
3465    -- Bug 4922099
3466    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
3467           (NVL(l_enc_upg_option, 'N') = 'O')
3468         ) AND
3469         (l_bflow_method_code = 'PRIOR_ENTRY')
3470       )
3471    THEN
3472       IF
3473       --
3474       1 = 2
3475       --
3476       THEN
3477       xla_accounting_err_pkg.build_message
3478                                     (p_appli_s_name            => 'XLA'
3479                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
3480                                     ,p_token_1                 => 'LINE_NUMBER'
3481                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
3482                                     ,p_token_2                 => 'LINE_TYPE_NAME'
3483                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
3484                                                                              l_component_type
3485                                                                             ,l_component_code
3486                                                                             ,l_component_type_code
3487                                                                             ,l_component_appl_id
3488                                                                             ,l_amb_context_code
3489                                                                             ,l_entity_code
3490                                                                             ,l_event_class_code
3491                                                                            )
3492                                     ,p_token_3                 => 'OWNER'
3493                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
3494                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
3495                                                                           ,p_lookup_code    => l_component_type_code
3496                                                                          )
3497                                     ,p_token_4                 => 'PRODUCT_NAME'
3498                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
3499                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
3500                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
3501                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
3502                                     ,p_ae_header_id            =>  NULL
3503                                        );
3504 
3505         IF (C_LEVEL_ERROR>= g_log_level) THEN
3506                  trace
3507                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
3508                       ,p_level    => C_LEVEL_ERROR
3509                       ,p_module   => l_log_module);
3510         END IF;
3511       END IF;
3512    END IF;
3513    --
3514    --
3515    ------------------------------------------------------------------------------------------------
3516    -- 4219869 Business Flow
3517    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
3518    -- Prior Entry.  Currently, the following code is always generated.
3519    ------------------------------------------------------------------------------------------------
3520    XLA_AE_LINES_PKG.ValidateCurrentLine;
3521 
3522    ------------------------------------------------------------------------------------
3523    -- 4219869 Business Flow
3524    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
3525    ------------------------------------------------------------------------------------
3526    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
3527 
3528    ----------------------------------------------------------------------------------
3529    -- 4219869 Business Flow
3530    -- Update journal entry status -- Need to generate this within IF <condition>
3531    ----------------------------------------------------------------------------------
3532    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
3533          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
3534          ,p_balance_type_code => l_balance_type_code
3535          );
3536 
3537    -------------------------------------------------------------------------------------------
3538    -- 4262811 - Generate the Accrual Reversal lines
3539    -------------------------------------------------------------------------------------------
3540    BEGIN
3541       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
3545       END IF;
3542                               (g_array_event(p_event_id).array_value_num('header_index'));
3543       IF l_acc_rev_flag IS NULL THEN
3544          l_acc_rev_flag := 'N';
3546    EXCEPTION
3547       WHEN OTHERS THEN
3548          l_acc_rev_flag := 'N';
3549    END;
3550    --
3551    IF (l_acc_rev_flag = 'Y') THEN
3552 
3553        -- 4645092  ------------------------------------------------------------------------------
3554        -- To allow MPA report to determine if it should generate report process
3555        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
3556        ------------------------------------------------------------------------------------------
3557 
3558        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
3559        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
3560 
3561        --
3562        -- Update the line information that should be overwritten
3563        --
3564        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
3565                                          p_header_num   => 1);
3566        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
3567 
3568        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
3569 
3570        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
3571           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
3572        END IF;
3573 
3574       --
3575       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
3576       --
3577       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
3578           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
3579       ELSE
3580           ---------------------------------------------------------------------------------------------------
3581           -- 4262811a Switch Sign
3582           ---------------------------------------------------------------------------------------------------
3583           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
3584           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
3585                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
3586           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
3587                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
3588           -- 5132302
3589           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
3590                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
3591 
3592       END IF;
3593 
3594       -- 4955764
3595       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
3596       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
3597 
3598 
3599       XLA_AE_LINES_PKG.ValidateCurrentLine;
3600       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
3601 
3602       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
3603                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
3604                ,p_balance_type_code => l_balance_type_code);
3605 
3606    END IF;
3607 
3608    -----------------------------------------------------------------------------------------
3609    -- 4262811 Multiperiod Accounting
3610    -----------------------------------------------------------------------------------------
3611      -- No MPA option is assigned.
3612 
3613 
3614 END IF;
3615 END IF;
3616 --
3617 
3618 --
3619 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3620    trace
3621       (p_msg      => 'END of AcctLineType_9'
3622       ,p_level    => C_LEVEL_PROCEDURE
3623       ,p_module   => l_log_module);
3624 END IF;
3625 --
3626 EXCEPTION
3627   WHEN xla_exceptions_pkg.application_exception THEN
3628       RAISE;
3629   WHEN OTHERS THEN
3630        xla_exceptions_pkg.raise_message
3631            (p_location => 'XLA_08407_AAD_S_000013_BC_PKG.AcctLineType_9');
3632 END AcctLineType_9;
3633 --
3634 
3635 ---------------------------------------
3636 --
3637 -- PRIVATE FUNCTION
3638 --         AcctLineType_10
3639 --
3640 ---------------------------------------
3641 PROCEDURE AcctLineType_10 (
3642   p_application_id        IN NUMBER
3643  ,p_event_id              IN NUMBER
3644  ,p_calculate_acctd_flag  IN VARCHAR2
3645  ,p_calculate_g_l_flag    IN VARCHAR2
3646  ,p_actual_flag           IN OUT VARCHAR2
3647  ,p_balance_type_code     OUT VARCHAR2
3648  ,p_gain_or_loss_ref      OUT VARCHAR2
3649  
3650 --TRANSACTION DESCRIPTION
3651  , p_source_1            IN VARCHAR2
3652 --CODE COMBINATION ID
3653  , p_source_5            IN NUMBER
3654 --CC FUNC CR AMT
3655  , p_source_6            IN NUMBER
3656 --PROJECT LINE
3657  , p_source_7            IN VARCHAR2
3658 --CC ACCT LINE ID
3659  , p_source_8            IN NUMBER
3660 --DOCUMENT TYPE
3661  , p_source_9            IN VARCHAR2
3662 --CC FUNC AMT
3663  , p_source_10            IN NUMBER
3664 --CURRENCY CODE
3665  , p_source_11            IN VARCHAR2
3666 )
3670 l_component_code              VARCHAR2(30);
3667 IS
3668 
3669 l_component_type              VARCHAR2(80);
3671 l_component_type_code         VARCHAR2(1);
3672 l_component_appl_id           INTEGER;
3673 l_amb_context_code            VARCHAR2(30);
3674 l_entity_code                 VARCHAR2(30);
3675 l_event_class_code            VARCHAR2(30);
3676 l_ae_header_id                NUMBER;
3677 l_event_type_code             VARCHAR2(30);
3678 l_line_definition_code        VARCHAR2(30);
3679 l_line_definition_owner_code  VARCHAR2(1);
3680 --
3681 -- adr variables
3682 l_segment                     VARCHAR2(30);
3683 l_ccid                        NUMBER;
3684 l_adr_transaction_coa_id      NUMBER;
3685 l_adr_accounting_coa_id       NUMBER;
3686 l_adr_flexfield_segment_code  VARCHAR2(30);
3687 l_adr_flex_value_set_id       NUMBER;
3688 l_adr_value_type_code         VARCHAR2(30);
3689 l_adr_value_combination_id    NUMBER;
3690 l_adr_value_segment_code      VARCHAR2(30);
3691 
3692 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
3693 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
3694 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
3695 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
3696 
3697 -- 4262811 Variables ------------------------------------------------------------------------------------------
3698 l_entered_amt_idx             NUMBER;
3699 l_accted_amt_idx              NUMBER;
3700 l_acc_rev_flag                VARCHAR2(1);
3701 l_accrual_line_num            NUMBER;
3702 l_tmp_amt                     NUMBER;
3703 l_acc_rev_natural_side_code   VARCHAR2(1);
3704 
3705 l_num_entries                 NUMBER;
3706 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
3707 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
3708 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
3709 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
3710 l_recog_line_1                NUMBER;
3711 l_recog_line_2                NUMBER;
3712 
3713 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
3714 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
3715 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
3716 
3717 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
3718 
3719 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
3720 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
3721 
3722 ---------------------------------------------------------------------------------------------------------------
3723 
3724 
3725 --
3726 -- bulk performance
3727 --
3728 l_balance_type_code           VARCHAR2(1);
3729 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
3730 l_log_module                  VARCHAR2(240);
3731 
3732 --
3733 -- Upgrade strategy
3734 --
3735 l_actual_upg_option           VARCHAR2(1);
3736 l_enc_upg_option           VARCHAR2(1);
3737 
3738 --
3739 BEGIN
3740 --
3741 IF g_log_enabled THEN
3742       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_10';
3743 END IF;
3744 --
3745 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3746 
3747       trace
3748          (p_msg      => 'BEGIN of AcctLineType_10'
3749          ,p_level    => C_LEVEL_PROCEDURE
3750          ,p_module   => l_log_module);
3751 
3752 END IF;
3753 --
3754 l_component_type             := 'AMB_JLT';
3755 l_component_code             := 'CC_CONTRACT_PRO_PA_CR';
3756 l_component_type_code        := 'S';
3757 l_component_appl_id          :=  8407;
3758 l_amb_context_code           := 'DEFAULT';
3759 l_entity_code                := 'CC_CONTRACTS';
3760 l_event_class_code           := 'CC_CONTRACT_PRO';
3761 l_event_type_code            := 'CC_CONTRACT_PRO_ALL';
3762 l_line_definition_owner_code := 'S';
3763 l_line_definition_code       := 'CC_CONTRACT_PRO_CMN';
3764 --
3765 l_balance_type_code          := 'E';
3766 l_segment                     := NULL;
3767 l_ccid                        := NULL;
3768 l_adr_transaction_coa_id      := NULL;
3769 l_adr_accounting_coa_id       := NULL;
3770 l_adr_flexfield_segment_code  := NULL;
3771 l_adr_flex_value_set_id       := NULL;
3772 l_adr_value_type_code         := NULL;
3773 l_adr_value_combination_id    := NULL;
3774 l_adr_value_segment_code      := NULL;
3775 
3776 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
3777 l_bflow_class_code           := '';    -- 4219869 Business Flow
3778 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
3779 l_budgetary_control_flag     := 'Y';
3780 
3781 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
3782 l_bflow_applied_to_amt       := NULL; -- 5132302
3783 l_entered_amt_idx            := NULL;          -- 4262811
3784 l_accted_amt_idx             := NULL;          -- 4262811
3785 l_acc_rev_flag               := NULL;          -- 4262811
3786 l_accrual_line_num           := NULL;          -- 4262811
3787 l_tmp_amt                    := NULL;          -- 4262811
3788 --
3789  
3790 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
3791     l_balance_type_code <> 'B' THEN
3792 IF p_source_6 IS NOT NULL AND 
3793 NVL(p_source_7,'
3797    --
3794 ') =  'Y'
3795  THEN 
3796 
3798    XLA_AE_LINES_PKG.SetNewLine;
3799 
3800    p_balance_type_code          := l_balance_type_code;
3801    -- set the flag so later we will know whether the gain loss line needs to be created
3802    
3803    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
3804      p_actual_flag :='A';
3805    END IF;
3806 
3807    --
3808    -- bulk performance
3809    --
3810    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
3811                                       p_header_num   => 0); -- 4262811
3812    --
3813    -- set accounting line options
3814    --
3815    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
3816            p_natural_side_code          => 'C'
3817          , p_gain_or_loss_flag          => 'N'
3818          , p_gl_transfer_mode_code      => 'D'
3819          , p_acct_entry_type_code       => 'E'
3820          , p_switch_side_flag           => 'N'
3821          , p_merge_duplicate_code       => 'N'
3822          );
3823    --
3824    l_acc_rev_natural_side_code := 'D';  -- 4262811
3825    -- 
3826    --
3827    -- set accounting line type info
3828    --
3829    xla_ae_lines_pkg.SetAcctLineType
3830       (p_component_type             => l_component_type
3831       ,p_event_type_code            => l_event_type_code
3832       ,p_line_definition_owner_code => l_line_definition_owner_code
3833       ,p_line_definition_code       => l_line_definition_code
3834       ,p_accounting_line_code       => l_component_code
3835       ,p_accounting_line_type_code  => l_component_type_code
3836       ,p_accounting_line_appl_id    => l_component_appl_id
3837       ,p_amb_context_code           => l_amb_context_code
3838       ,p_entity_code                => l_entity_code
3839       ,p_event_class_code           => l_event_class_code);
3840    --
3841    -- set accounting class
3842    --
3843    xla_ae_lines_pkg.SetAcctClass(
3844            p_accounting_class_code  => 'REQUISITION'
3845          , p_ae_header_id           => l_ae_header_id
3846          );
3847 
3848    --
3849    -- set rounding class
3850    --
3851    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
3852                       'REQUISITION';
3853 
3854    --
3855    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
3856    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
3857    --
3858    -- bulk performance
3859    --
3860    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
3861 
3862    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
3863       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
3864 
3865    -- 4955764
3866    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
3867       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
3868 
3869    -- 4458381 Public Sector Enh
3870       XLA_AE_LINES_PKG.g_rec_lines.array_encumbrance_type_id(XLA_AE_LINES_PKG.g_LineNumber) := 1061;
3871    --
3872    -- set accounting attributes for the line type
3873    --
3874    l_entered_amt_idx := 3;
3875    l_accted_amt_idx  := 5;
3876    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
3877    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
3878    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_8);
3879    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
3880    l_rec_acct_attrs.array_char_value(2)  := p_source_9;
3881    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
3882    l_rec_acct_attrs.array_num_value(3)  := p_source_10;
3883    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
3884    l_rec_acct_attrs.array_char_value(4)  := p_source_11;
3885    l_rec_acct_attrs.array_acct_attr_code(5) := 'LEDGER_AMOUNT';
3886    l_rec_acct_attrs.array_num_value(5)  := p_source_10;
3887 
3888    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
3889    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
3890 
3891    ---------------------------------------------------------------------------------------------------------------
3892    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
3893    ---------------------------------------------------------------------------------------------------------------
3894    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
3895 
3896    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
3897    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
3898 
3899    IF xla_accounting_cache_pkg.GetValueChar
3900          (p_source_code         => 'LEDGER_CATEGORY_CODE'
3901          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
3902    AND l_bflow_method_code = 'PRIOR_ENTRY'
3903 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
3904    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
3905          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
3906        )
3907    THEN
3908          xla_ae_lines_pkg.BflowUpgEntry
3912    ELSE
3909            (p_business_method_code    => l_bflow_method_code
3910            ,p_business_class_code     => l_bflow_class_code
3911            ,p_balance_type            => l_balance_type_code);
3913       NULL;
3914 -- No business flow processing for business flow method of NONE.
3915    END IF;
3916 
3917    --
3918    -- call analytical criteria
3919    --
3920    
3921    --
3922    -- call description
3923    --
3924    
3925 xla_ae_lines_pkg.SetLineDescription(
3926    p_ae_header_id => l_ae_header_id
3927   ,p_description  => Description_1 (
3928      p_application_id         => p_application_id
3929    , p_ae_header_id           => l_ae_header_id 
3930 , p_source_1 => p_source_1
3931    )
3932 );
3933 
3934 
3935    --
3936    -- call ADRs
3937    -- Bug 4922099
3938    --
3939    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
3940         (NVL(l_actual_upg_option, 'N') = 'O') OR
3941         (NVL(l_enc_upg_option, 'N') = 'O')
3942       )
3943    THEN
3944    NULL;
3945    --
3946    --
3947    
3948   l_ccid := AcctDerRule_3(
3949            p_application_id           => p_application_id
3950          , p_ae_header_id             => l_ae_header_id 
3951 , p_source_5 => p_source_5
3952          , x_transaction_coa_id       => l_adr_transaction_coa_id
3953          , x_accounting_coa_id        => l_adr_accounting_coa_id
3954          , x_value_type_code          => l_adr_value_type_code
3955          , p_side                     => 'NA'
3956    );
3957 
3958    xla_ae_lines_pkg.set_ccid(
3959     p_code_combination_id          => l_ccid
3960   , p_value_type_code              => l_adr_value_type_code
3961   , p_transaction_coa_id           => l_adr_transaction_coa_id
3962   , p_accounting_coa_id            => l_adr_accounting_coa_id
3963   , p_adr_code                     => 'CC_COMMON_ADR'
3964   , p_adr_type_code                => 'S'
3965   , p_component_type               => l_component_type
3966   , p_component_code               => l_component_code
3967   , p_component_type_code          => l_component_type_code
3968   , p_component_appl_id            => l_component_appl_id
3969   , p_amb_context_code             => l_amb_context_code
3970   , p_side                         => 'NA'
3971   );
3972 
3973 
3974    --
3975    --
3976    END IF;
3977    --
3978    -- Bug 4922099
3979    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
3980           (NVL(l_enc_upg_option, 'N') = 'O')
3981         ) AND
3982         (l_bflow_method_code = 'PRIOR_ENTRY')
3983       )
3984    THEN
3985       IF
3986       --
3987       1 = 2
3988       --
3989       THEN
3990       xla_accounting_err_pkg.build_message
3991                                     (p_appli_s_name            => 'XLA'
3992                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
3993                                     ,p_token_1                 => 'LINE_NUMBER'
3994                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
3995                                     ,p_token_2                 => 'LINE_TYPE_NAME'
3996                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
3997                                                                              l_component_type
3998                                                                             ,l_component_code
3999                                                                             ,l_component_type_code
4000                                                                             ,l_component_appl_id
4001                                                                             ,l_amb_context_code
4002                                                                             ,l_entity_code
4003                                                                             ,l_event_class_code
4004                                                                            )
4005                                     ,p_token_3                 => 'OWNER'
4006                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
4007                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
4008                                                                           ,p_lookup_code    => l_component_type_code
4009                                                                          )
4010                                     ,p_token_4                 => 'PRODUCT_NAME'
4011                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
4012                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
4013                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
4014                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
4015                                     ,p_ae_header_id            =>  NULL
4016                                        );
4017 
4018         IF (C_LEVEL_ERROR>= g_log_level) THEN
4019                  trace
4020                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
4021                       ,p_level    => C_LEVEL_ERROR
4022                       ,p_module   => l_log_module);
4023         END IF;
4024       END IF;
4025    END IF;
4026    --
4027    --
4031    -- Prior Entry.  Currently, the following code is always generated.
4028    ------------------------------------------------------------------------------------------------
4029    -- 4219869 Business Flow
4030    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
4032    ------------------------------------------------------------------------------------------------
4033    XLA_AE_LINES_PKG.ValidateCurrentLine;
4034 
4035    ------------------------------------------------------------------------------------
4036    -- 4219869 Business Flow
4037    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
4038    ------------------------------------------------------------------------------------
4039    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
4040 
4041    ----------------------------------------------------------------------------------
4042    -- 4219869 Business Flow
4043    -- Update journal entry status -- Need to generate this within IF <condition>
4044    ----------------------------------------------------------------------------------
4045    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
4046          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
4047          ,p_balance_type_code => l_balance_type_code
4048          );
4049 
4050    -------------------------------------------------------------------------------------------
4051    -- 4262811 - Generate the Accrual Reversal lines
4052    -------------------------------------------------------------------------------------------
4053    BEGIN
4054       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
4055                               (g_array_event(p_event_id).array_value_num('header_index'));
4056       IF l_acc_rev_flag IS NULL THEN
4057          l_acc_rev_flag := 'N';
4058       END IF;
4059    EXCEPTION
4060       WHEN OTHERS THEN
4061          l_acc_rev_flag := 'N';
4062    END;
4063    --
4064    IF (l_acc_rev_flag = 'Y') THEN
4065 
4066        -- 4645092  ------------------------------------------------------------------------------
4067        -- To allow MPA report to determine if it should generate report process
4068        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
4069        ------------------------------------------------------------------------------------------
4070 
4071        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
4072        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
4073 
4074        --
4075        -- Update the line information that should be overwritten
4076        --
4077        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
4078                                          p_header_num   => 1);
4079        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
4080 
4081        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
4082 
4083        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
4084           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
4085        END IF;
4086 
4087       --
4088       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
4089       --
4090       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
4091           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
4092       ELSE
4093           ---------------------------------------------------------------------------------------------------
4094           -- 4262811a Switch Sign
4095           ---------------------------------------------------------------------------------------------------
4096           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
4097           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
4098                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
4099           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
4100                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
4101           -- 5132302
4102           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
4103                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
4104 
4105       END IF;
4106 
4107       -- 4955764
4108       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
4109       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
4110 
4111 
4112       XLA_AE_LINES_PKG.ValidateCurrentLine;
4113       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
4114 
4115       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
4116                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
4117                ,p_balance_type_code => l_balance_type_code);
4118 
4119    END IF;
4120 
4121    -----------------------------------------------------------------------------------------
4122    -- 4262811 Multiperiod Accounting
4123    -----------------------------------------------------------------------------------------
4124      -- No MPA option is assigned.
4125 
4126 
4127 END IF;
4128 END IF;
4132 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4129 --
4130 
4131 --
4133    trace
4134       (p_msg      => 'END of AcctLineType_10'
4135       ,p_level    => C_LEVEL_PROCEDURE
4136       ,p_module   => l_log_module);
4137 END IF;
4138 --
4139 EXCEPTION
4140   WHEN xla_exceptions_pkg.application_exception THEN
4141       RAISE;
4142   WHEN OTHERS THEN
4143        xla_exceptions_pkg.raise_message
4144            (p_location => 'XLA_08407_AAD_S_000013_BC_PKG.AcctLineType_10');
4145 END AcctLineType_10;
4146 --
4147 
4148 ---------------------------------------
4149 --
4150 -- PRIVATE FUNCTION
4151 --         AcctLineType_11
4152 --
4153 ---------------------------------------
4154 PROCEDURE AcctLineType_11 (
4155   p_application_id        IN NUMBER
4156  ,p_event_id              IN NUMBER
4157  ,p_calculate_acctd_flag  IN VARCHAR2
4158  ,p_calculate_g_l_flag    IN VARCHAR2
4159  ,p_actual_flag           IN OUT VARCHAR2
4160  ,p_balance_type_code     OUT VARCHAR2
4161  ,p_gain_or_loss_ref      OUT VARCHAR2
4162  
4163 --TRANSACTION DESCRIPTION
4164  , p_source_1            IN VARCHAR2
4165 --CODE COMBINATION ID
4166  , p_source_5            IN NUMBER
4167 --PROJECT LINE
4168  , p_source_7            IN VARCHAR2
4169 --CC ACCT LINE ID
4170  , p_source_8            IN NUMBER
4171 --DOCUMENT TYPE
4172  , p_source_9            IN VARCHAR2
4173 --CC FUNC AMT
4174  , p_source_10            IN NUMBER
4175 --CURRENCY CODE
4176  , p_source_11            IN VARCHAR2
4177 --CC FUNC DR AMT
4178  , p_source_12            IN NUMBER
4179 )
4180 IS
4181 
4182 l_component_type              VARCHAR2(80);
4183 l_component_code              VARCHAR2(30);
4184 l_component_type_code         VARCHAR2(1);
4185 l_component_appl_id           INTEGER;
4186 l_amb_context_code            VARCHAR2(30);
4187 l_entity_code                 VARCHAR2(30);
4188 l_event_class_code            VARCHAR2(30);
4189 l_ae_header_id                NUMBER;
4190 l_event_type_code             VARCHAR2(30);
4191 l_line_definition_code        VARCHAR2(30);
4192 l_line_definition_owner_code  VARCHAR2(1);
4193 --
4194 -- adr variables
4195 l_segment                     VARCHAR2(30);
4196 l_ccid                        NUMBER;
4197 l_adr_transaction_coa_id      NUMBER;
4198 l_adr_accounting_coa_id       NUMBER;
4199 l_adr_flexfield_segment_code  VARCHAR2(30);
4200 l_adr_flex_value_set_id       NUMBER;
4201 l_adr_value_type_code         VARCHAR2(30);
4202 l_adr_value_combination_id    NUMBER;
4203 l_adr_value_segment_code      VARCHAR2(30);
4204 
4205 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
4206 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
4207 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
4208 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
4209 
4210 -- 4262811 Variables ------------------------------------------------------------------------------------------
4211 l_entered_amt_idx             NUMBER;
4212 l_accted_amt_idx              NUMBER;
4213 l_acc_rev_flag                VARCHAR2(1);
4214 l_accrual_line_num            NUMBER;
4215 l_tmp_amt                     NUMBER;
4216 l_acc_rev_natural_side_code   VARCHAR2(1);
4217 
4218 l_num_entries                 NUMBER;
4219 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
4220 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
4221 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
4222 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
4223 l_recog_line_1                NUMBER;
4224 l_recog_line_2                NUMBER;
4225 
4226 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
4227 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
4228 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
4229 
4230 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
4231 
4232 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
4233 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
4234 
4235 ---------------------------------------------------------------------------------------------------------------
4236 
4237 
4238 --
4239 -- bulk performance
4240 --
4241 l_balance_type_code           VARCHAR2(1);
4242 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
4243 l_log_module                  VARCHAR2(240);
4244 
4245 --
4246 -- Upgrade strategy
4247 --
4248 l_actual_upg_option           VARCHAR2(1);
4249 l_enc_upg_option           VARCHAR2(1);
4250 
4251 --
4252 BEGIN
4253 --
4254 IF g_log_enabled THEN
4255       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_11';
4256 END IF;
4257 --
4258 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4259 
4260       trace
4261          (p_msg      => 'BEGIN of AcctLineType_11'
4262          ,p_level    => C_LEVEL_PROCEDURE
4263          ,p_module   => l_log_module);
4264 
4265 END IF;
4266 --
4267 l_component_type             := 'AMB_JLT';
4268 l_component_code             := 'CC_CONTRACT_PRO_PA_DR';
4272 l_entity_code                := 'CC_CONTRACTS';
4269 l_component_type_code        := 'S';
4270 l_component_appl_id          :=  8407;
4271 l_amb_context_code           := 'DEFAULT';
4273 l_event_class_code           := 'CC_CONTRACT_PRO';
4274 l_event_type_code            := 'CC_CONTRACT_PRO_ALL';
4275 l_line_definition_owner_code := 'S';
4276 l_line_definition_code       := 'CC_CONTRACT_PRO_CMN';
4277 --
4278 l_balance_type_code          := 'E';
4279 l_segment                     := NULL;
4280 l_ccid                        := NULL;
4281 l_adr_transaction_coa_id      := NULL;
4282 l_adr_accounting_coa_id       := NULL;
4283 l_adr_flexfield_segment_code  := NULL;
4284 l_adr_flex_value_set_id       := NULL;
4285 l_adr_value_type_code         := NULL;
4286 l_adr_value_combination_id    := NULL;
4287 l_adr_value_segment_code      := NULL;
4288 
4289 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
4290 l_bflow_class_code           := '';    -- 4219869 Business Flow
4291 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
4292 l_budgetary_control_flag     := 'Y';
4293 
4294 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
4295 l_bflow_applied_to_amt       := NULL; -- 5132302
4296 l_entered_amt_idx            := NULL;          -- 4262811
4297 l_accted_amt_idx             := NULL;          -- 4262811
4298 l_acc_rev_flag               := NULL;          -- 4262811
4299 l_accrual_line_num           := NULL;          -- 4262811
4300 l_tmp_amt                    := NULL;          -- 4262811
4301 --
4302  
4303 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
4304     l_balance_type_code <> 'B' THEN
4305 IF p_source_12 IS NOT NULL AND 
4306 NVL(p_source_7,'
4307 ') =  'Y'
4308  THEN 
4309 
4310    --
4311    XLA_AE_LINES_PKG.SetNewLine;
4312 
4313    p_balance_type_code          := l_balance_type_code;
4314    -- set the flag so later we will know whether the gain loss line needs to be created
4315    
4316    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
4317      p_actual_flag :='A';
4318    END IF;
4319 
4320    --
4321    -- bulk performance
4322    --
4323    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
4324                                       p_header_num   => 0); -- 4262811
4325    --
4326    -- set accounting line options
4327    --
4328    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
4329            p_natural_side_code          => 'D'
4330          , p_gain_or_loss_flag          => 'N'
4331          , p_gl_transfer_mode_code      => 'D'
4332          , p_acct_entry_type_code       => 'E'
4333          , p_switch_side_flag           => 'N'
4334          , p_merge_duplicate_code       => 'N'
4335          );
4336    --
4337    l_acc_rev_natural_side_code := 'C';  -- 4262811
4338    -- 
4339    --
4340    -- set accounting line type info
4341    --
4342    xla_ae_lines_pkg.SetAcctLineType
4343       (p_component_type             => l_component_type
4344       ,p_event_type_code            => l_event_type_code
4345       ,p_line_definition_owner_code => l_line_definition_owner_code
4346       ,p_line_definition_code       => l_line_definition_code
4347       ,p_accounting_line_code       => l_component_code
4348       ,p_accounting_line_type_code  => l_component_type_code
4349       ,p_accounting_line_appl_id    => l_component_appl_id
4350       ,p_amb_context_code           => l_amb_context_code
4351       ,p_entity_code                => l_entity_code
4352       ,p_event_class_code           => l_event_class_code);
4353    --
4354    -- set accounting class
4355    --
4356    xla_ae_lines_pkg.SetAcctClass(
4357            p_accounting_class_code  => 'REQUISITION'
4358          , p_ae_header_id           => l_ae_header_id
4359          );
4360 
4361    --
4362    -- set rounding class
4363    --
4364    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
4365                       'REQUISITION';
4366 
4367    --
4368    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
4369    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
4370    --
4371    -- bulk performance
4372    --
4373    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
4374 
4375    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
4376       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
4377 
4378    -- 4955764
4379    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
4380       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
4381 
4382    -- 4458381 Public Sector Enh
4383       XLA_AE_LINES_PKG.g_rec_lines.array_encumbrance_type_id(XLA_AE_LINES_PKG.g_LineNumber) := 1061;
4384    --
4385    -- set accounting attributes for the line type
4386    --
4387    l_entered_amt_idx := 3;
4388    l_accted_amt_idx  := 5;
4389    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
4390    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
4391    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_8);
4392    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
4396    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
4393    l_rec_acct_attrs.array_char_value(2)  := p_source_9;
4394    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
4395    l_rec_acct_attrs.array_num_value(3)  := p_source_10;
4397    l_rec_acct_attrs.array_char_value(4)  := p_source_11;
4398    l_rec_acct_attrs.array_acct_attr_code(5) := 'LEDGER_AMOUNT';
4399    l_rec_acct_attrs.array_num_value(5)  := p_source_10;
4400 
4401    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
4402    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
4403 
4404    ---------------------------------------------------------------------------------------------------------------
4405    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
4406    ---------------------------------------------------------------------------------------------------------------
4407    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
4408 
4409    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
4410    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
4411 
4412    IF xla_accounting_cache_pkg.GetValueChar
4413          (p_source_code         => 'LEDGER_CATEGORY_CODE'
4414          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
4415    AND l_bflow_method_code = 'PRIOR_ENTRY'
4416 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
4417    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
4418          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
4419        )
4420    THEN
4421          xla_ae_lines_pkg.BflowUpgEntry
4422            (p_business_method_code    => l_bflow_method_code
4423            ,p_business_class_code     => l_bflow_class_code
4424            ,p_balance_type            => l_balance_type_code);
4425    ELSE
4426       NULL;
4427 -- No business flow processing for business flow method of NONE.
4428    END IF;
4429 
4430    --
4431    -- call analytical criteria
4432    --
4433    
4434    --
4435    -- call description
4436    --
4437    
4438 xla_ae_lines_pkg.SetLineDescription(
4439    p_ae_header_id => l_ae_header_id
4440   ,p_description  => Description_1 (
4441      p_application_id         => p_application_id
4442    , p_ae_header_id           => l_ae_header_id 
4443 , p_source_1 => p_source_1
4444    )
4445 );
4446 
4447 
4448    --
4449    -- call ADRs
4450    -- Bug 4922099
4451    --
4452    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
4453         (NVL(l_actual_upg_option, 'N') = 'O') OR
4454         (NVL(l_enc_upg_option, 'N') = 'O')
4455       )
4456    THEN
4457    NULL;
4458    --
4459    --
4460    
4461   l_ccid := AcctDerRule_3(
4462            p_application_id           => p_application_id
4463          , p_ae_header_id             => l_ae_header_id 
4464 , p_source_5 => p_source_5
4465          , x_transaction_coa_id       => l_adr_transaction_coa_id
4466          , x_accounting_coa_id        => l_adr_accounting_coa_id
4467          , x_value_type_code          => l_adr_value_type_code
4468          , p_side                     => 'NA'
4469    );
4470 
4471    xla_ae_lines_pkg.set_ccid(
4472     p_code_combination_id          => l_ccid
4473   , p_value_type_code              => l_adr_value_type_code
4474   , p_transaction_coa_id           => l_adr_transaction_coa_id
4475   , p_accounting_coa_id            => l_adr_accounting_coa_id
4476   , p_adr_code                     => 'CC_COMMON_ADR'
4477   , p_adr_type_code                => 'S'
4478   , p_component_type               => l_component_type
4479   , p_component_code               => l_component_code
4480   , p_component_type_code          => l_component_type_code
4481   , p_component_appl_id            => l_component_appl_id
4482   , p_amb_context_code             => l_amb_context_code
4483   , p_side                         => 'NA'
4484   );
4485 
4486 
4487    --
4488    --
4489    END IF;
4490    --
4491    -- Bug 4922099
4492    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
4493           (NVL(l_enc_upg_option, 'N') = 'O')
4494         ) AND
4495         (l_bflow_method_code = 'PRIOR_ENTRY')
4496       )
4497    THEN
4498       IF
4499       --
4500       1 = 2
4501       --
4502       THEN
4503       xla_accounting_err_pkg.build_message
4504                                     (p_appli_s_name            => 'XLA'
4505                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
4506                                     ,p_token_1                 => 'LINE_NUMBER'
4507                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
4508                                     ,p_token_2                 => 'LINE_TYPE_NAME'
4509                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
4510                                                                              l_component_type
4511                                                                             ,l_component_code
4512                                                                             ,l_component_type_code
4516                                                                             ,l_event_class_code
4513                                                                             ,l_component_appl_id
4514                                                                             ,l_amb_context_code
4515                                                                             ,l_entity_code
4517                                                                            )
4518                                     ,p_token_3                 => 'OWNER'
4519                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
4520                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
4521                                                                           ,p_lookup_code    => l_component_type_code
4522                                                                          )
4523                                     ,p_token_4                 => 'PRODUCT_NAME'
4524                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
4525                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
4526                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
4527                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
4528                                     ,p_ae_header_id            =>  NULL
4529                                        );
4530 
4531         IF (C_LEVEL_ERROR>= g_log_level) THEN
4532                  trace
4533                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
4534                       ,p_level    => C_LEVEL_ERROR
4535                       ,p_module   => l_log_module);
4536         END IF;
4537       END IF;
4538    END IF;
4539    --
4540    --
4541    ------------------------------------------------------------------------------------------------
4542    -- 4219869 Business Flow
4543    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
4544    -- Prior Entry.  Currently, the following code is always generated.
4545    ------------------------------------------------------------------------------------------------
4546    XLA_AE_LINES_PKG.ValidateCurrentLine;
4547 
4548    ------------------------------------------------------------------------------------
4549    -- 4219869 Business Flow
4550    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
4551    ------------------------------------------------------------------------------------
4552    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
4553 
4554    ----------------------------------------------------------------------------------
4555    -- 4219869 Business Flow
4556    -- Update journal entry status -- Need to generate this within IF <condition>
4557    ----------------------------------------------------------------------------------
4558    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
4559          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
4560          ,p_balance_type_code => l_balance_type_code
4561          );
4562 
4563    -------------------------------------------------------------------------------------------
4564    -- 4262811 - Generate the Accrual Reversal lines
4565    -------------------------------------------------------------------------------------------
4566    BEGIN
4567       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
4568                               (g_array_event(p_event_id).array_value_num('header_index'));
4569       IF l_acc_rev_flag IS NULL THEN
4570          l_acc_rev_flag := 'N';
4571       END IF;
4572    EXCEPTION
4573       WHEN OTHERS THEN
4574          l_acc_rev_flag := 'N';
4575    END;
4576    --
4577    IF (l_acc_rev_flag = 'Y') THEN
4578 
4579        -- 4645092  ------------------------------------------------------------------------------
4580        -- To allow MPA report to determine if it should generate report process
4581        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
4582        ------------------------------------------------------------------------------------------
4583 
4584        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
4585        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
4586 
4587        --
4588        -- Update the line information that should be overwritten
4589        --
4590        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
4591                                          p_header_num   => 1);
4592        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
4593 
4594        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
4595 
4596        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
4597           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
4598        END IF;
4599 
4600       --
4601       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
4602       --
4603       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
4604           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
4605       ELSE
4609           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
4606           ---------------------------------------------------------------------------------------------------
4607           -- 4262811a Switch Sign
4608           ---------------------------------------------------------------------------------------------------
4610           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
4611                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
4612           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
4613                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
4614           -- 5132302
4615           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
4616                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
4617 
4618       END IF;
4619 
4620       -- 4955764
4621       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
4622       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
4623 
4624 
4625       XLA_AE_LINES_PKG.ValidateCurrentLine;
4626       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
4627 
4628       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
4629                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
4630                ,p_balance_type_code => l_balance_type_code);
4631 
4632    END IF;
4633 
4634    -----------------------------------------------------------------------------------------
4635    -- 4262811 Multiperiod Accounting
4636    -----------------------------------------------------------------------------------------
4637      -- No MPA option is assigned.
4638 
4639 
4640 END IF;
4641 END IF;
4642 --
4643 
4644 --
4645 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4646    trace
4647       (p_msg      => 'END of AcctLineType_11'
4648       ,p_level    => C_LEVEL_PROCEDURE
4649       ,p_module   => l_log_module);
4650 END IF;
4651 --
4652 EXCEPTION
4653   WHEN xla_exceptions_pkg.application_exception THEN
4654       RAISE;
4655   WHEN OTHERS THEN
4656        xla_exceptions_pkg.raise_message
4657            (p_location => 'XLA_08407_AAD_S_000013_BC_PKG.AcctLineType_11');
4658 END AcctLineType_11;
4659 --
4660 
4661 ---------------------------------------
4662 --
4663 -- PRIVATE FUNCTION
4664 --         AcctLineType_12
4665 --
4666 ---------------------------------------
4667 PROCEDURE AcctLineType_12 (
4668   p_application_id        IN NUMBER
4669  ,p_event_id              IN NUMBER
4670  ,p_calculate_acctd_flag  IN VARCHAR2
4671  ,p_calculate_g_l_flag    IN VARCHAR2
4672  ,p_actual_flag           IN OUT VARCHAR2
4673  ,p_balance_type_code     OUT VARCHAR2
4674  ,p_gain_or_loss_ref      OUT VARCHAR2
4675  
4676 --TRANSACTION DESCRIPTION
4677  , p_source_1            IN VARCHAR2
4678 --CODE COMBINATION ID
4679  , p_source_5            IN NUMBER
4680 --CC FUNC CR AMT
4681  , p_source_6            IN NUMBER
4682 --CC ACCT LINE ID
4683  , p_source_8            IN NUMBER
4684 --DOCUMENT TYPE
4685  , p_source_9            IN VARCHAR2
4686 --CC FUNC AMT
4687  , p_source_10            IN NUMBER
4688 --CURRENCY CODE
4689  , p_source_11            IN VARCHAR2
4690 )
4691 IS
4692 
4693 l_component_type              VARCHAR2(80);
4694 l_component_code              VARCHAR2(30);
4695 l_component_type_code         VARCHAR2(1);
4696 l_component_appl_id           INTEGER;
4697 l_amb_context_code            VARCHAR2(30);
4698 l_entity_code                 VARCHAR2(30);
4699 l_event_class_code            VARCHAR2(30);
4700 l_ae_header_id                NUMBER;
4701 l_event_type_code             VARCHAR2(30);
4702 l_line_definition_code        VARCHAR2(30);
4703 l_line_definition_owner_code  VARCHAR2(1);
4704 --
4705 -- adr variables
4706 l_segment                     VARCHAR2(30);
4707 l_ccid                        NUMBER;
4708 l_adr_transaction_coa_id      NUMBER;
4709 l_adr_accounting_coa_id       NUMBER;
4710 l_adr_flexfield_segment_code  VARCHAR2(30);
4711 l_adr_flex_value_set_id       NUMBER;
4712 l_adr_value_type_code         VARCHAR2(30);
4713 l_adr_value_combination_id    NUMBER;
4714 l_adr_value_segment_code      VARCHAR2(30);
4715 
4716 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
4717 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
4718 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
4719 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
4720 
4721 -- 4262811 Variables ------------------------------------------------------------------------------------------
4722 l_entered_amt_idx             NUMBER;
4723 l_accted_amt_idx              NUMBER;
4724 l_acc_rev_flag                VARCHAR2(1);
4725 l_accrual_line_num            NUMBER;
4726 l_tmp_amt                     NUMBER;
4727 l_acc_rev_natural_side_code   VARCHAR2(1);
4728 
4729 l_num_entries                 NUMBER;
4730 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
4731 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
4732 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
4736 
4733 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
4734 l_recog_line_1                NUMBER;
4735 l_recog_line_2                NUMBER;
4737 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
4738 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
4739 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
4740 
4741 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
4742 
4743 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
4744 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
4745 
4746 ---------------------------------------------------------------------------------------------------------------
4747 
4748 
4749 --
4750 -- bulk performance
4751 --
4752 l_balance_type_code           VARCHAR2(1);
4753 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
4754 l_log_module                  VARCHAR2(240);
4755 
4756 --
4757 -- Upgrade strategy
4758 --
4759 l_actual_upg_option           VARCHAR2(1);
4760 l_enc_upg_option           VARCHAR2(1);
4761 
4762 --
4763 BEGIN
4764 --
4765 IF g_log_enabled THEN
4766       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_12';
4767 END IF;
4768 --
4769 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4770 
4771       trace
4772          (p_msg      => 'BEGIN of AcctLineType_12'
4773          ,p_level    => C_LEVEL_PROCEDURE
4774          ,p_module   => l_log_module);
4775 
4776 END IF;
4777 --
4778 l_component_type             := 'AMB_JLT';
4779 l_component_code             := 'CC_PA_BUDGET_CR';
4780 l_component_type_code        := 'S';
4781 l_component_appl_id          :=  8407;
4782 l_amb_context_code           := 'DEFAULT';
4783 l_entity_code                := 'CC_PROJECTS';
4784 l_event_class_code           := 'CC_PROJECT_BUDGET';
4785 l_event_type_code            := 'CC_PROJECT_BUDGET_ALL';
4786 l_line_definition_owner_code := 'S';
4787 l_line_definition_code       := 'CC_PROJECT_BUDGET_BASELINE';
4788 --
4789 l_balance_type_code          := 'E';
4790 l_segment                     := NULL;
4791 l_ccid                        := NULL;
4792 l_adr_transaction_coa_id      := NULL;
4793 l_adr_accounting_coa_id       := NULL;
4794 l_adr_flexfield_segment_code  := NULL;
4795 l_adr_flex_value_set_id       := NULL;
4796 l_adr_value_type_code         := NULL;
4797 l_adr_value_combination_id    := NULL;
4798 l_adr_value_segment_code      := NULL;
4799 
4800 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
4801 l_bflow_class_code           := '';    -- 4219869 Business Flow
4802 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
4803 l_budgetary_control_flag     := 'Y';
4804 
4805 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
4806 l_bflow_applied_to_amt       := NULL; -- 5132302
4807 l_entered_amt_idx            := NULL;          -- 4262811
4808 l_accted_amt_idx             := NULL;          -- 4262811
4809 l_acc_rev_flag               := NULL;          -- 4262811
4810 l_accrual_line_num           := NULL;          -- 4262811
4811 l_tmp_amt                    := NULL;          -- 4262811
4812 --
4813  
4814 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
4815     l_balance_type_code <> 'B' THEN
4816 IF p_source_6 IS NOT NULL 
4817  THEN 
4818 
4819    --
4820    XLA_AE_LINES_PKG.SetNewLine;
4821 
4822    p_balance_type_code          := l_balance_type_code;
4823    -- set the flag so later we will know whether the gain loss line needs to be created
4824    
4825    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
4826      p_actual_flag :='A';
4827    END IF;
4828 
4829    --
4830    -- bulk performance
4831    --
4832    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
4833                                       p_header_num   => 0); -- 4262811
4834    --
4835    -- set accounting line options
4836    --
4837    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
4838            p_natural_side_code          => 'C'
4839          , p_gain_or_loss_flag          => 'N'
4840          , p_gl_transfer_mode_code      => 'D'
4841          , p_acct_entry_type_code       => 'E'
4842          , p_switch_side_flag           => 'N'
4843          , p_merge_duplicate_code       => 'N'
4844          );
4845    --
4846    l_acc_rev_natural_side_code := 'D';  -- 4262811
4847    -- 
4848    --
4849    -- set accounting line type info
4850    --
4851    xla_ae_lines_pkg.SetAcctLineType
4852       (p_component_type             => l_component_type
4853       ,p_event_type_code            => l_event_type_code
4854       ,p_line_definition_owner_code => l_line_definition_owner_code
4855       ,p_line_definition_code       => l_line_definition_code
4856       ,p_accounting_line_code       => l_component_code
4857       ,p_accounting_line_type_code  => l_component_type_code
4858       ,p_accounting_line_appl_id    => l_component_appl_id
4859       ,p_amb_context_code           => l_amb_context_code
4860       ,p_entity_code                => l_entity_code
4861       ,p_event_class_code           => l_event_class_code);
4862    --
4866            p_accounting_class_code  => 'BUDGET'
4863    -- set accounting class
4864    --
4865    xla_ae_lines_pkg.SetAcctClass(
4867          , p_ae_header_id           => l_ae_header_id
4868          );
4869 
4870    --
4871    -- set rounding class
4872    --
4873    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
4874                       'BUDGET';
4875 
4876    --
4877    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
4878    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
4879    --
4880    -- bulk performance
4881    --
4882    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
4883 
4884    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
4885       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
4886 
4887    -- 4955764
4888    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
4889       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
4890 
4891    -- 4458381 Public Sector Enh
4892       XLA_AE_LINES_PKG.g_rec_lines.array_encumbrance_type_id(XLA_AE_LINES_PKG.g_LineNumber) := 1061;
4893    --
4894    -- set accounting attributes for the line type
4895    --
4896    l_entered_amt_idx := 3;
4897    l_accted_amt_idx  := 5;
4898    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
4899    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
4900    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_8);
4901    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
4902    l_rec_acct_attrs.array_char_value(2)  := p_source_9;
4903    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
4904    l_rec_acct_attrs.array_num_value(3)  := p_source_10;
4905    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
4906    l_rec_acct_attrs.array_char_value(4)  := p_source_11;
4907    l_rec_acct_attrs.array_acct_attr_code(5) := 'LEDGER_AMOUNT';
4908    l_rec_acct_attrs.array_num_value(5)  := p_source_10;
4909 
4910    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
4911    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
4912 
4913    ---------------------------------------------------------------------------------------------------------------
4914    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
4915    ---------------------------------------------------------------------------------------------------------------
4916    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
4917 
4918    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
4919    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
4920 
4921    IF xla_accounting_cache_pkg.GetValueChar
4922          (p_source_code         => 'LEDGER_CATEGORY_CODE'
4923          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
4924    AND l_bflow_method_code = 'PRIOR_ENTRY'
4925 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
4926    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
4927          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
4928        )
4929    THEN
4930          xla_ae_lines_pkg.BflowUpgEntry
4931            (p_business_method_code    => l_bflow_method_code
4932            ,p_business_class_code     => l_bflow_class_code
4933            ,p_balance_type            => l_balance_type_code);
4934    ELSE
4935       NULL;
4936 -- No business flow processing for business flow method of NONE.
4937    END IF;
4938 
4939    --
4940    -- call analytical criteria
4941    --
4942    
4943    --
4944    -- call description
4945    --
4946    
4947 xla_ae_lines_pkg.SetLineDescription(
4948    p_ae_header_id => l_ae_header_id
4949   ,p_description  => Description_1 (
4950      p_application_id         => p_application_id
4951    , p_ae_header_id           => l_ae_header_id 
4952 , p_source_1 => p_source_1
4953    )
4954 );
4955 
4956 
4957    --
4958    -- call ADRs
4959    -- Bug 4922099
4960    --
4961    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
4962         (NVL(l_actual_upg_option, 'N') = 'O') OR
4963         (NVL(l_enc_upg_option, 'N') = 'O')
4964       )
4965    THEN
4966    NULL;
4967    --
4968    --
4969    
4970   l_ccid := AcctDerRule_3(
4971            p_application_id           => p_application_id
4972          , p_ae_header_id             => l_ae_header_id 
4973 , p_source_5 => p_source_5
4974          , x_transaction_coa_id       => l_adr_transaction_coa_id
4975          , x_accounting_coa_id        => l_adr_accounting_coa_id
4976          , x_value_type_code          => l_adr_value_type_code
4977          , p_side                     => 'NA'
4978    );
4979 
4980    xla_ae_lines_pkg.set_ccid(
4981     p_code_combination_id          => l_ccid
4982   , p_value_type_code              => l_adr_value_type_code
4983   , p_transaction_coa_id           => l_adr_transaction_coa_id
4984   , p_accounting_coa_id            => l_adr_accounting_coa_id
4985   , p_adr_code                     => 'CC_COMMON_ADR'
4986   , p_adr_type_code                => 'S'
4990   , p_component_appl_id            => l_component_appl_id
4987   , p_component_type               => l_component_type
4988   , p_component_code               => l_component_code
4989   , p_component_type_code          => l_component_type_code
4991   , p_amb_context_code             => l_amb_context_code
4992   , p_side                         => 'NA'
4993   );
4994 
4995 
4996    --
4997    --
4998    END IF;
4999    --
5000    -- Bug 4922099
5001    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
5002           (NVL(l_enc_upg_option, 'N') = 'O')
5003         ) AND
5004         (l_bflow_method_code = 'PRIOR_ENTRY')
5005       )
5006    THEN
5007       IF
5008       --
5009       1 = 2
5010       --
5011       THEN
5012       xla_accounting_err_pkg.build_message
5013                                     (p_appli_s_name            => 'XLA'
5014                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
5015                                     ,p_token_1                 => 'LINE_NUMBER'
5016                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
5017                                     ,p_token_2                 => 'LINE_TYPE_NAME'
5018                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
5019                                                                              l_component_type
5020                                                                             ,l_component_code
5021                                                                             ,l_component_type_code
5022                                                                             ,l_component_appl_id
5023                                                                             ,l_amb_context_code
5024                                                                             ,l_entity_code
5025                                                                             ,l_event_class_code
5026                                                                            )
5027                                     ,p_token_3                 => 'OWNER'
5028                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
5029                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
5030                                                                           ,p_lookup_code    => l_component_type_code
5031                                                                          )
5032                                     ,p_token_4                 => 'PRODUCT_NAME'
5033                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
5034                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
5035                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
5036                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
5037                                     ,p_ae_header_id            =>  NULL
5038                                        );
5039 
5040         IF (C_LEVEL_ERROR>= g_log_level) THEN
5041                  trace
5042                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
5043                       ,p_level    => C_LEVEL_ERROR
5044                       ,p_module   => l_log_module);
5045         END IF;
5046       END IF;
5047    END IF;
5048    --
5049    --
5050    ------------------------------------------------------------------------------------------------
5051    -- 4219869 Business Flow
5052    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
5053    -- Prior Entry.  Currently, the following code is always generated.
5054    ------------------------------------------------------------------------------------------------
5055    XLA_AE_LINES_PKG.ValidateCurrentLine;
5056 
5057    ------------------------------------------------------------------------------------
5058    -- 4219869 Business Flow
5059    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
5060    ------------------------------------------------------------------------------------
5061    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
5062 
5063    ----------------------------------------------------------------------------------
5064    -- 4219869 Business Flow
5065    -- Update journal entry status -- Need to generate this within IF <condition>
5066    ----------------------------------------------------------------------------------
5067    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
5068          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
5069          ,p_balance_type_code => l_balance_type_code
5070          );
5071 
5072    -------------------------------------------------------------------------------------------
5073    -- 4262811 - Generate the Accrual Reversal lines
5074    -------------------------------------------------------------------------------------------
5075    BEGIN
5076       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
5077                               (g_array_event(p_event_id).array_value_num('header_index'));
5078       IF l_acc_rev_flag IS NULL THEN
5079          l_acc_rev_flag := 'N';
5080       END IF;
5081    EXCEPTION
5082       WHEN OTHERS THEN
5083          l_acc_rev_flag := 'N';
5084    END;
5085    --
5089        -- To allow MPA report to determine if it should generate report process
5086    IF (l_acc_rev_flag = 'Y') THEN
5087 
5088        -- 4645092  ------------------------------------------------------------------------------
5090        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
5091        ------------------------------------------------------------------------------------------
5092 
5093        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
5094        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
5095 
5096        --
5097        -- Update the line information that should be overwritten
5098        --
5099        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
5100                                          p_header_num   => 1);
5101        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
5102 
5103        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
5104 
5105        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
5106           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
5107        END IF;
5108 
5109       --
5110       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
5111       --
5112       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
5113           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
5114       ELSE
5115           ---------------------------------------------------------------------------------------------------
5116           -- 4262811a Switch Sign
5117           ---------------------------------------------------------------------------------------------------
5118           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
5119           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
5120                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
5121           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
5122                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
5123           -- 5132302
5124           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
5125                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
5126 
5127       END IF;
5128 
5129       -- 4955764
5130       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
5131       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
5132 
5133 
5134       XLA_AE_LINES_PKG.ValidateCurrentLine;
5135       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
5136 
5137       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
5138                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
5139                ,p_balance_type_code => l_balance_type_code);
5140 
5141    END IF;
5142 
5143    -----------------------------------------------------------------------------------------
5144    -- 4262811 Multiperiod Accounting
5145    -----------------------------------------------------------------------------------------
5146      -- No MPA option is assigned.
5147 
5148 
5149 END IF;
5150 END IF;
5151 --
5152 
5153 --
5154 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5155    trace
5156       (p_msg      => 'END of AcctLineType_12'
5157       ,p_level    => C_LEVEL_PROCEDURE
5158       ,p_module   => l_log_module);
5159 END IF;
5160 --
5161 EXCEPTION
5162   WHEN xla_exceptions_pkg.application_exception THEN
5163       RAISE;
5164   WHEN OTHERS THEN
5165        xla_exceptions_pkg.raise_message
5166            (p_location => 'XLA_08407_AAD_S_000013_BC_PKG.AcctLineType_12');
5167 END AcctLineType_12;
5168 --
5169 
5170 ---------------------------------------
5171 --
5172 -- PRIVATE FUNCTION
5173 --         AcctLineType_13
5174 --
5175 ---------------------------------------
5176 PROCEDURE AcctLineType_13 (
5177   p_application_id        IN NUMBER
5178  ,p_event_id              IN NUMBER
5179  ,p_calculate_acctd_flag  IN VARCHAR2
5180  ,p_calculate_g_l_flag    IN VARCHAR2
5181  ,p_actual_flag           IN OUT VARCHAR2
5182  ,p_balance_type_code     OUT VARCHAR2
5183  ,p_gain_or_loss_ref      OUT VARCHAR2
5184  
5185 --TRANSACTION DESCRIPTION
5186  , p_source_1            IN VARCHAR2
5187 --CODE COMBINATION ID
5188  , p_source_5            IN NUMBER
5189 --CC ACCT LINE ID
5190  , p_source_8            IN NUMBER
5191 --DOCUMENT TYPE
5192  , p_source_9            IN VARCHAR2
5193 --CC FUNC AMT
5194  , p_source_10            IN NUMBER
5195 --CURRENCY CODE
5196  , p_source_11            IN VARCHAR2
5197 --CC FUNC DR AMT
5198  , p_source_12            IN NUMBER
5199 )
5200 IS
5201 
5202 l_component_type              VARCHAR2(80);
5203 l_component_code              VARCHAR2(30);
5204 l_component_type_code         VARCHAR2(1);
5205 l_component_appl_id           INTEGER;
5206 l_amb_context_code            VARCHAR2(30);
5207 l_entity_code                 VARCHAR2(30);
5211 l_line_definition_code        VARCHAR2(30);
5208 l_event_class_code            VARCHAR2(30);
5209 l_ae_header_id                NUMBER;
5210 l_event_type_code             VARCHAR2(30);
5212 l_line_definition_owner_code  VARCHAR2(1);
5213 --
5214 -- adr variables
5215 l_segment                     VARCHAR2(30);
5216 l_ccid                        NUMBER;
5217 l_adr_transaction_coa_id      NUMBER;
5218 l_adr_accounting_coa_id       NUMBER;
5219 l_adr_flexfield_segment_code  VARCHAR2(30);
5220 l_adr_flex_value_set_id       NUMBER;
5221 l_adr_value_type_code         VARCHAR2(30);
5222 l_adr_value_combination_id    NUMBER;
5223 l_adr_value_segment_code      VARCHAR2(30);
5224 
5225 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
5226 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
5227 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
5228 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
5229 
5230 -- 4262811 Variables ------------------------------------------------------------------------------------------
5231 l_entered_amt_idx             NUMBER;
5232 l_accted_amt_idx              NUMBER;
5233 l_acc_rev_flag                VARCHAR2(1);
5234 l_accrual_line_num            NUMBER;
5235 l_tmp_amt                     NUMBER;
5236 l_acc_rev_natural_side_code   VARCHAR2(1);
5237 
5238 l_num_entries                 NUMBER;
5239 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
5240 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
5241 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
5242 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
5243 l_recog_line_1                NUMBER;
5244 l_recog_line_2                NUMBER;
5245 
5246 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
5247 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
5248 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
5249 
5250 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
5251 
5252 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
5253 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
5254 
5255 ---------------------------------------------------------------------------------------------------------------
5256 
5257 
5258 --
5259 -- bulk performance
5260 --
5261 l_balance_type_code           VARCHAR2(1);
5262 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
5263 l_log_module                  VARCHAR2(240);
5264 
5265 --
5266 -- Upgrade strategy
5267 --
5268 l_actual_upg_option           VARCHAR2(1);
5269 l_enc_upg_option           VARCHAR2(1);
5270 
5271 --
5272 BEGIN
5273 --
5274 IF g_log_enabled THEN
5275       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_13';
5276 END IF;
5277 --
5278 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5279 
5280       trace
5281          (p_msg      => 'BEGIN of AcctLineType_13'
5282          ,p_level    => C_LEVEL_PROCEDURE
5283          ,p_module   => l_log_module);
5284 
5285 END IF;
5286 --
5287 l_component_type             := 'AMB_JLT';
5288 l_component_code             := 'CC_PA_BUDGET_DR';
5289 l_component_type_code        := 'S';
5290 l_component_appl_id          :=  8407;
5291 l_amb_context_code           := 'DEFAULT';
5292 l_entity_code                := 'CC_PROJECTS';
5293 l_event_class_code           := 'CC_PROJECT_BUDGET';
5294 l_event_type_code            := 'CC_PROJECT_BUDGET_ALL';
5295 l_line_definition_owner_code := 'S';
5296 l_line_definition_code       := 'CC_PROJECT_BUDGET_BASELINE';
5297 --
5298 l_balance_type_code          := 'E';
5299 l_segment                     := NULL;
5300 l_ccid                        := NULL;
5301 l_adr_transaction_coa_id      := NULL;
5302 l_adr_accounting_coa_id       := NULL;
5303 l_adr_flexfield_segment_code  := NULL;
5304 l_adr_flex_value_set_id       := NULL;
5305 l_adr_value_type_code         := NULL;
5306 l_adr_value_combination_id    := NULL;
5307 l_adr_value_segment_code      := NULL;
5308 
5309 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
5310 l_bflow_class_code           := '';    -- 4219869 Business Flow
5311 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
5312 l_budgetary_control_flag     := 'Y';
5313 
5314 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
5315 l_bflow_applied_to_amt       := NULL; -- 5132302
5316 l_entered_amt_idx            := NULL;          -- 4262811
5317 l_accted_amt_idx             := NULL;          -- 4262811
5318 l_acc_rev_flag               := NULL;          -- 4262811
5319 l_accrual_line_num           := NULL;          -- 4262811
5320 l_tmp_amt                    := NULL;          -- 4262811
5321 --
5322  
5323 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
5324     l_balance_type_code <> 'B' THEN
5325 IF p_source_12 IS NOT NULL 
5326  THEN 
5327 
5328    --
5329    XLA_AE_LINES_PKG.SetNewLine;
5330 
5331    p_balance_type_code          := l_balance_type_code;
5332    -- set the flag so later we will know whether the gain loss line needs to be created
5333    
5334    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
5338    --
5335      p_actual_flag :='A';
5336    END IF;
5337 
5339    -- bulk performance
5340    --
5341    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
5342                                       p_header_num   => 0); -- 4262811
5343    --
5344    -- set accounting line options
5345    --
5346    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
5347            p_natural_side_code          => 'D'
5348          , p_gain_or_loss_flag          => 'N'
5349          , p_gl_transfer_mode_code      => 'D'
5350          , p_acct_entry_type_code       => 'E'
5351          , p_switch_side_flag           => 'N'
5352          , p_merge_duplicate_code       => 'N'
5353          );
5354    --
5355    l_acc_rev_natural_side_code := 'C';  -- 4262811
5356    -- 
5357    --
5358    -- set accounting line type info
5359    --
5360    xla_ae_lines_pkg.SetAcctLineType
5361       (p_component_type             => l_component_type
5362       ,p_event_type_code            => l_event_type_code
5363       ,p_line_definition_owner_code => l_line_definition_owner_code
5364       ,p_line_definition_code       => l_line_definition_code
5365       ,p_accounting_line_code       => l_component_code
5366       ,p_accounting_line_type_code  => l_component_type_code
5367       ,p_accounting_line_appl_id    => l_component_appl_id
5368       ,p_amb_context_code           => l_amb_context_code
5369       ,p_entity_code                => l_entity_code
5370       ,p_event_class_code           => l_event_class_code);
5371    --
5372    -- set accounting class
5373    --
5374    xla_ae_lines_pkg.SetAcctClass(
5375            p_accounting_class_code  => 'BUDGET'
5376          , p_ae_header_id           => l_ae_header_id
5377          );
5378 
5379    --
5380    -- set rounding class
5381    --
5382    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
5383                       'BUDGET';
5384 
5385    --
5386    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
5387    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
5388    --
5389    -- bulk performance
5390    --
5391    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
5392 
5393    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
5394       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
5395 
5396    -- 4955764
5397    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
5398       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
5399 
5400    -- 4458381 Public Sector Enh
5401       XLA_AE_LINES_PKG.g_rec_lines.array_encumbrance_type_id(XLA_AE_LINES_PKG.g_LineNumber) := 1061;
5402    --
5403    -- set accounting attributes for the line type
5404    --
5405    l_entered_amt_idx := 3;
5406    l_accted_amt_idx  := 5;
5407    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
5408    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
5409    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_8);
5410    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
5411    l_rec_acct_attrs.array_char_value(2)  := p_source_9;
5412    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
5413    l_rec_acct_attrs.array_num_value(3)  := p_source_10;
5414    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
5415    l_rec_acct_attrs.array_char_value(4)  := p_source_11;
5416    l_rec_acct_attrs.array_acct_attr_code(5) := 'LEDGER_AMOUNT';
5417    l_rec_acct_attrs.array_num_value(5)  := p_source_10;
5418 
5419    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
5420    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
5421 
5422    ---------------------------------------------------------------------------------------------------------------
5423    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
5424    ---------------------------------------------------------------------------------------------------------------
5425    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
5426 
5427    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
5428    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
5429 
5430    IF xla_accounting_cache_pkg.GetValueChar
5431          (p_source_code         => 'LEDGER_CATEGORY_CODE'
5432          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
5433    AND l_bflow_method_code = 'PRIOR_ENTRY'
5434 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
5435    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
5436          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
5437        )
5438    THEN
5439          xla_ae_lines_pkg.BflowUpgEntry
5440            (p_business_method_code    => l_bflow_method_code
5441            ,p_business_class_code     => l_bflow_class_code
5442            ,p_balance_type            => l_balance_type_code);
5443    ELSE
5444       NULL;
5445 -- No business flow processing for business flow method of NONE.
5446    END IF;
5447 
5448    --
5449    -- call analytical criteria
5450    --
5451    
5452    --
5453    -- call description
5454    --
5455    
5459      p_application_id         => p_application_id
5456 xla_ae_lines_pkg.SetLineDescription(
5457    p_ae_header_id => l_ae_header_id
5458   ,p_description  => Description_1 (
5460    , p_ae_header_id           => l_ae_header_id 
5461 , p_source_1 => p_source_1
5462    )
5463 );
5464 
5465 
5466    --
5467    -- call ADRs
5468    -- Bug 4922099
5469    --
5470    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
5471         (NVL(l_actual_upg_option, 'N') = 'O') OR
5472         (NVL(l_enc_upg_option, 'N') = 'O')
5473       )
5474    THEN
5475    NULL;
5476    --
5477    --
5478    
5479   l_ccid := AcctDerRule_3(
5480            p_application_id           => p_application_id
5481          , p_ae_header_id             => l_ae_header_id 
5482 , p_source_5 => p_source_5
5483          , x_transaction_coa_id       => l_adr_transaction_coa_id
5484          , x_accounting_coa_id        => l_adr_accounting_coa_id
5485          , x_value_type_code          => l_adr_value_type_code
5486          , p_side                     => 'NA'
5487    );
5488 
5489    xla_ae_lines_pkg.set_ccid(
5490     p_code_combination_id          => l_ccid
5491   , p_value_type_code              => l_adr_value_type_code
5492   , p_transaction_coa_id           => l_adr_transaction_coa_id
5493   , p_accounting_coa_id            => l_adr_accounting_coa_id
5494   , p_adr_code                     => 'CC_COMMON_ADR'
5495   , p_adr_type_code                => 'S'
5496   , p_component_type               => l_component_type
5497   , p_component_code               => l_component_code
5498   , p_component_type_code          => l_component_type_code
5499   , p_component_appl_id            => l_component_appl_id
5500   , p_amb_context_code             => l_amb_context_code
5501   , p_side                         => 'NA'
5502   );
5503 
5504 
5505    --
5506    --
5507    END IF;
5508    --
5509    -- Bug 4922099
5510    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
5511           (NVL(l_enc_upg_option, 'N') = 'O')
5512         ) AND
5513         (l_bflow_method_code = 'PRIOR_ENTRY')
5514       )
5515    THEN
5516       IF
5517       --
5518       1 = 2
5519       --
5520       THEN
5521       xla_accounting_err_pkg.build_message
5522                                     (p_appli_s_name            => 'XLA'
5523                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
5524                                     ,p_token_1                 => 'LINE_NUMBER'
5525                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
5526                                     ,p_token_2                 => 'LINE_TYPE_NAME'
5527                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
5528                                                                              l_component_type
5529                                                                             ,l_component_code
5530                                                                             ,l_component_type_code
5531                                                                             ,l_component_appl_id
5532                                                                             ,l_amb_context_code
5533                                                                             ,l_entity_code
5534                                                                             ,l_event_class_code
5535                                                                            )
5536                                     ,p_token_3                 => 'OWNER'
5537                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
5538                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
5539                                                                           ,p_lookup_code    => l_component_type_code
5540                                                                          )
5541                                     ,p_token_4                 => 'PRODUCT_NAME'
5542                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
5543                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
5544                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
5545                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
5546                                     ,p_ae_header_id            =>  NULL
5547                                        );
5548 
5549         IF (C_LEVEL_ERROR>= g_log_level) THEN
5550                  trace
5551                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
5552                       ,p_level    => C_LEVEL_ERROR
5553                       ,p_module   => l_log_module);
5554         END IF;
5555       END IF;
5556    END IF;
5557    --
5558    --
5559    ------------------------------------------------------------------------------------------------
5560    -- 4219869 Business Flow
5561    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
5562    -- Prior Entry.  Currently, the following code is always generated.
5563    ------------------------------------------------------------------------------------------------
5564    XLA_AE_LINES_PKG.ValidateCurrentLine;
5565 
5569    ------------------------------------------------------------------------------------
5566    ------------------------------------------------------------------------------------
5567    -- 4219869 Business Flow
5568    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
5570    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
5571 
5572    ----------------------------------------------------------------------------------
5573    -- 4219869 Business Flow
5574    -- Update journal entry status -- Need to generate this within IF <condition>
5575    ----------------------------------------------------------------------------------
5576    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
5577          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
5578          ,p_balance_type_code => l_balance_type_code
5579          );
5580 
5581    -------------------------------------------------------------------------------------------
5582    -- 4262811 - Generate the Accrual Reversal lines
5583    -------------------------------------------------------------------------------------------
5584    BEGIN
5585       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
5586                               (g_array_event(p_event_id).array_value_num('header_index'));
5587       IF l_acc_rev_flag IS NULL THEN
5588          l_acc_rev_flag := 'N';
5589       END IF;
5590    EXCEPTION
5591       WHEN OTHERS THEN
5592          l_acc_rev_flag := 'N';
5593    END;
5594    --
5595    IF (l_acc_rev_flag = 'Y') THEN
5596 
5597        -- 4645092  ------------------------------------------------------------------------------
5598        -- To allow MPA report to determine if it should generate report process
5599        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
5600        ------------------------------------------------------------------------------------------
5601 
5602        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
5603        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
5604 
5605        --
5606        -- Update the line information that should be overwritten
5607        --
5608        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
5609                                          p_header_num   => 1);
5610        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
5611 
5612        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
5613 
5614        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
5615           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
5616        END IF;
5617 
5618       --
5619       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
5620       --
5621       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
5622           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
5623       ELSE
5624           ---------------------------------------------------------------------------------------------------
5625           -- 4262811a Switch Sign
5626           ---------------------------------------------------------------------------------------------------
5627           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
5628           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
5629                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
5630           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
5631                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
5632           -- 5132302
5633           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
5634                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
5635 
5636       END IF;
5637 
5638       -- 4955764
5639       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
5640       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
5641 
5642 
5643       XLA_AE_LINES_PKG.ValidateCurrentLine;
5644       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
5645 
5646       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
5647                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
5648                ,p_balance_type_code => l_balance_type_code);
5649 
5650    END IF;
5651 
5652    -----------------------------------------------------------------------------------------
5653    -- 4262811 Multiperiod Accounting
5654    -----------------------------------------------------------------------------------------
5655      -- No MPA option is assigned.
5656 
5657 
5658 END IF;
5659 END IF;
5660 --
5661 
5662 --
5663 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5664    trace
5665       (p_msg      => 'END of AcctLineType_13'
5666       ,p_level    => C_LEVEL_PROCEDURE
5667       ,p_module   => l_log_module);
5668 END IF;
5669 --
5670 EXCEPTION
5671   WHEN xla_exceptions_pkg.application_exception THEN
5672       RAISE;
5673   WHEN OTHERS THEN
5674        xla_exceptions_pkg.raise_message
5678 
5675            (p_location => 'XLA_08407_AAD_S_000013_BC_PKG.AcctLineType_13');
5676 END AcctLineType_13;
5677 --
5679 ---------------------------------------
5680 --
5681 -- PRIVATE FUNCTION
5682 --         AcctLineType_14
5683 --
5684 ---------------------------------------
5685 PROCEDURE AcctLineType_14 (
5686   p_application_id        IN NUMBER
5687  ,p_event_id              IN NUMBER
5688  ,p_calculate_acctd_flag  IN VARCHAR2
5689  ,p_calculate_g_l_flag    IN VARCHAR2
5690  ,p_actual_flag           IN OUT VARCHAR2
5691  ,p_balance_type_code     OUT VARCHAR2
5692  ,p_gain_or_loss_ref      OUT VARCHAR2
5693  
5694 --TRANSACTION DESCRIPTION
5695  , p_source_1            IN VARCHAR2
5696 --CODE COMBINATION ID
5697  , p_source_5            IN NUMBER
5698 --CC FUNC CR AMT
5699  , p_source_6            IN NUMBER
5700 --CC ACCT LINE ID
5701  , p_source_8            IN NUMBER
5702 --DOCUMENT TYPE
5703  , p_source_9            IN VARCHAR2
5704 --CC FUNC AMT
5705  , p_source_10            IN NUMBER
5706 --CURRENCY CODE
5707  , p_source_11            IN VARCHAR2
5708 )
5709 IS
5710 
5711 l_component_type              VARCHAR2(80);
5712 l_component_code              VARCHAR2(30);
5713 l_component_type_code         VARCHAR2(1);
5714 l_component_appl_id           INTEGER;
5715 l_amb_context_code            VARCHAR2(30);
5716 l_entity_code                 VARCHAR2(30);
5717 l_event_class_code            VARCHAR2(30);
5718 l_ae_header_id                NUMBER;
5719 l_event_type_code             VARCHAR2(30);
5720 l_line_definition_code        VARCHAR2(30);
5721 l_line_definition_owner_code  VARCHAR2(1);
5722 --
5723 -- adr variables
5724 l_segment                     VARCHAR2(30);
5725 l_ccid                        NUMBER;
5726 l_adr_transaction_coa_id      NUMBER;
5727 l_adr_accounting_coa_id       NUMBER;
5728 l_adr_flexfield_segment_code  VARCHAR2(30);
5729 l_adr_flex_value_set_id       NUMBER;
5730 l_adr_value_type_code         VARCHAR2(30);
5731 l_adr_value_combination_id    NUMBER;
5732 l_adr_value_segment_code      VARCHAR2(30);
5733 
5734 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
5735 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
5736 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
5737 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
5738 
5739 -- 4262811 Variables ------------------------------------------------------------------------------------------
5740 l_entered_amt_idx             NUMBER;
5741 l_accted_amt_idx              NUMBER;
5742 l_acc_rev_flag                VARCHAR2(1);
5743 l_accrual_line_num            NUMBER;
5744 l_tmp_amt                     NUMBER;
5745 l_acc_rev_natural_side_code   VARCHAR2(1);
5746 
5747 l_num_entries                 NUMBER;
5748 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
5749 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
5750 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
5751 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
5752 l_recog_line_1                NUMBER;
5753 l_recog_line_2                NUMBER;
5754 
5755 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
5756 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
5757 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
5758 
5759 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
5760 
5761 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
5762 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
5763 
5764 ---------------------------------------------------------------------------------------------------------------
5765 
5766 
5767 --
5768 -- bulk performance
5769 --
5770 l_balance_type_code           VARCHAR2(1);
5771 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
5772 l_log_module                  VARCHAR2(240);
5773 
5774 --
5775 -- Upgrade strategy
5776 --
5777 l_actual_upg_option           VARCHAR2(1);
5778 l_enc_upg_option           VARCHAR2(1);
5779 
5780 --
5781 BEGIN
5782 --
5783 IF g_log_enabled THEN
5784       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_14';
5785 END IF;
5786 --
5787 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5788 
5789       trace
5790          (p_msg      => 'BEGIN of AcctLineType_14'
5791          ,p_level    => C_LEVEL_PROCEDURE
5792          ,p_module   => l_log_module);
5793 
5794 END IF;
5795 --
5796 l_component_type             := 'AMB_JLT';
5797 l_component_code             := 'CC_PURCHASE_ORDER_CR';
5798 l_component_type_code        := 'S';
5799 l_component_appl_id          :=  8407;
5800 l_amb_context_code           := 'DEFAULT';
5801 l_entity_code                := 'CC_PURCHASE_ORDERS';
5802 l_event_class_code           := 'CC_PURCHASE_ORDERS';
5803 l_event_type_code            := 'CC_PURCHASE_ORDERS_ALL';
5804 l_line_definition_owner_code := 'S';
5805 l_line_definition_code       := 'CC_PURCHASE_ORDER_CMN';
5806 --
5807 l_balance_type_code          := 'E';
5808 l_segment                     := NULL;
5809 l_ccid                        := NULL;
5810 l_adr_transaction_coa_id      := NULL;
5814 l_adr_value_type_code         := NULL;
5811 l_adr_accounting_coa_id       := NULL;
5812 l_adr_flexfield_segment_code  := NULL;
5813 l_adr_flex_value_set_id       := NULL;
5815 l_adr_value_combination_id    := NULL;
5816 l_adr_value_segment_code      := NULL;
5817 
5818 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
5819 l_bflow_class_code           := '';    -- 4219869 Business Flow
5820 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
5821 l_budgetary_control_flag     := 'Y';
5822 
5823 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
5824 l_bflow_applied_to_amt       := NULL; -- 5132302
5825 l_entered_amt_idx            := NULL;          -- 4262811
5826 l_accted_amt_idx             := NULL;          -- 4262811
5827 l_acc_rev_flag               := NULL;          -- 4262811
5828 l_accrual_line_num           := NULL;          -- 4262811
5829 l_tmp_amt                    := NULL;          -- 4262811
5830 --
5831  
5832 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
5833     l_balance_type_code <> 'B' THEN
5834 IF p_source_6 IS NOT NULL 
5835  THEN 
5836 
5837    --
5838    XLA_AE_LINES_PKG.SetNewLine;
5839 
5840    p_balance_type_code          := l_balance_type_code;
5841    -- set the flag so later we will know whether the gain loss line needs to be created
5842    
5843    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
5844      p_actual_flag :='A';
5845    END IF;
5846 
5847    --
5848    -- bulk performance
5849    --
5850    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
5851                                       p_header_num   => 0); -- 4262811
5852    --
5853    -- set accounting line options
5854    --
5855    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
5856            p_natural_side_code          => 'C'
5857          , p_gain_or_loss_flag          => 'N'
5858          , p_gl_transfer_mode_code      => 'D'
5859          , p_acct_entry_type_code       => 'E'
5860          , p_switch_side_flag           => 'N'
5861          , p_merge_duplicate_code       => 'N'
5862          );
5863    --
5864    l_acc_rev_natural_side_code := 'D';  -- 4262811
5865    -- 
5866    --
5867    -- set accounting line type info
5868    --
5869    xla_ae_lines_pkg.SetAcctLineType
5870       (p_component_type             => l_component_type
5871       ,p_event_type_code            => l_event_type_code
5872       ,p_line_definition_owner_code => l_line_definition_owner_code
5873       ,p_line_definition_code       => l_line_definition_code
5874       ,p_accounting_line_code       => l_component_code
5875       ,p_accounting_line_type_code  => l_component_type_code
5876       ,p_accounting_line_appl_id    => l_component_appl_id
5877       ,p_amb_context_code           => l_amb_context_code
5878       ,p_entity_code                => l_entity_code
5879       ,p_event_class_code           => l_event_class_code);
5880    --
5881    -- set accounting class
5882    --
5883    xla_ae_lines_pkg.SetAcctClass(
5884            p_accounting_class_code  => 'PURCHASE_ORDER'
5885          , p_ae_header_id           => l_ae_header_id
5886          );
5887 
5888    --
5889    -- set rounding class
5890    --
5891    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
5892                       'PURCHASE_ORDER';
5893 
5894    --
5895    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
5896    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
5897    --
5898    -- bulk performance
5899    --
5900    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
5901 
5902    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
5903       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
5904 
5905    -- 4955764
5906    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
5907       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
5908 
5909    -- 4458381 Public Sector Enh
5910       XLA_AE_LINES_PKG.g_rec_lines.array_encumbrance_type_id(XLA_AE_LINES_PKG.g_LineNumber) := 1001;
5911    --
5912    -- set accounting attributes for the line type
5913    --
5914    l_entered_amt_idx := 3;
5915    l_accted_amt_idx  := 5;
5916    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
5917    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
5918    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_8);
5919    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
5920    l_rec_acct_attrs.array_char_value(2)  := p_source_9;
5921    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
5922    l_rec_acct_attrs.array_num_value(3)  := p_source_10;
5923    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
5924    l_rec_acct_attrs.array_char_value(4)  := p_source_11;
5925    l_rec_acct_attrs.array_acct_attr_code(5) := 'LEDGER_AMOUNT';
5926    l_rec_acct_attrs.array_num_value(5)  := p_source_10;
5927 
5928    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
5929    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
5930 
5931    ---------------------------------------------------------------------------------------------------------------
5935 
5932    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
5933    ---------------------------------------------------------------------------------------------------------------
5934    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
5936    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
5937    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
5938 
5939    IF xla_accounting_cache_pkg.GetValueChar
5940          (p_source_code         => 'LEDGER_CATEGORY_CODE'
5941          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
5942    AND l_bflow_method_code = 'PRIOR_ENTRY'
5943 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
5944    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
5945          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
5946        )
5947    THEN
5948          xla_ae_lines_pkg.BflowUpgEntry
5949            (p_business_method_code    => l_bflow_method_code
5950            ,p_business_class_code     => l_bflow_class_code
5951            ,p_balance_type            => l_balance_type_code);
5952    ELSE
5953       NULL;
5954 -- No business flow processing for business flow method of NONE.
5955    END IF;
5956 
5957    --
5958    -- call analytical criteria
5959    --
5960    
5961    --
5962    -- call description
5963    --
5964    
5965 xla_ae_lines_pkg.SetLineDescription(
5966    p_ae_header_id => l_ae_header_id
5967   ,p_description  => Description_1 (
5968      p_application_id         => p_application_id
5969    , p_ae_header_id           => l_ae_header_id 
5970 , p_source_1 => p_source_1
5971    )
5972 );
5973 
5974 
5975    --
5976    -- call ADRs
5977    -- Bug 4922099
5978    --
5979    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
5980         (NVL(l_actual_upg_option, 'N') = 'O') OR
5981         (NVL(l_enc_upg_option, 'N') = 'O')
5982       )
5983    THEN
5984    NULL;
5985    --
5986    --
5987    
5988   l_ccid := AcctDerRule_3(
5989            p_application_id           => p_application_id
5990          , p_ae_header_id             => l_ae_header_id 
5991 , p_source_5 => p_source_5
5992          , x_transaction_coa_id       => l_adr_transaction_coa_id
5993          , x_accounting_coa_id        => l_adr_accounting_coa_id
5994          , x_value_type_code          => l_adr_value_type_code
5995          , p_side                     => 'NA'
5996    );
5997 
5998    xla_ae_lines_pkg.set_ccid(
5999     p_code_combination_id          => l_ccid
6000   , p_value_type_code              => l_adr_value_type_code
6001   , p_transaction_coa_id           => l_adr_transaction_coa_id
6002   , p_accounting_coa_id            => l_adr_accounting_coa_id
6003   , p_adr_code                     => 'CC_COMMON_ADR'
6004   , p_adr_type_code                => 'S'
6005   , p_component_type               => l_component_type
6006   , p_component_code               => l_component_code
6007   , p_component_type_code          => l_component_type_code
6008   , p_component_appl_id            => l_component_appl_id
6009   , p_amb_context_code             => l_amb_context_code
6010   , p_side                         => 'NA'
6011   );
6012 
6013 
6014    --
6015    --
6016    END IF;
6017    --
6018    -- Bug 4922099
6019    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
6020           (NVL(l_enc_upg_option, 'N') = 'O')
6021         ) AND
6022         (l_bflow_method_code = 'PRIOR_ENTRY')
6023       )
6024    THEN
6025       IF
6026       --
6027       1 = 2
6028       --
6029       THEN
6030       xla_accounting_err_pkg.build_message
6031                                     (p_appli_s_name            => 'XLA'
6032                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
6033                                     ,p_token_1                 => 'LINE_NUMBER'
6034                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
6035                                     ,p_token_2                 => 'LINE_TYPE_NAME'
6036                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
6037                                                                              l_component_type
6038                                                                             ,l_component_code
6039                                                                             ,l_component_type_code
6040                                                                             ,l_component_appl_id
6041                                                                             ,l_amb_context_code
6042                                                                             ,l_entity_code
6043                                                                             ,l_event_class_code
6044                                                                            )
6045                                     ,p_token_3                 => 'OWNER'
6046                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
6047                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
6048                                                                           ,p_lookup_code    => l_component_type_code
6052                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
6049                                                                          )
6050                                     ,p_token_4                 => 'PRODUCT_NAME'
6051                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
6053                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
6054                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
6055                                     ,p_ae_header_id            =>  NULL
6056                                        );
6057 
6058         IF (C_LEVEL_ERROR>= g_log_level) THEN
6059                  trace
6060                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
6061                       ,p_level    => C_LEVEL_ERROR
6062                       ,p_module   => l_log_module);
6063         END IF;
6064       END IF;
6065    END IF;
6066    --
6067    --
6068    ------------------------------------------------------------------------------------------------
6069    -- 4219869 Business Flow
6070    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
6071    -- Prior Entry.  Currently, the following code is always generated.
6072    ------------------------------------------------------------------------------------------------
6073    XLA_AE_LINES_PKG.ValidateCurrentLine;
6074 
6075    ------------------------------------------------------------------------------------
6076    -- 4219869 Business Flow
6077    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
6078    ------------------------------------------------------------------------------------
6079    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
6080 
6081    ----------------------------------------------------------------------------------
6082    -- 4219869 Business Flow
6083    -- Update journal entry status -- Need to generate this within IF <condition>
6084    ----------------------------------------------------------------------------------
6085    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
6086          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
6087          ,p_balance_type_code => l_balance_type_code
6088          );
6089 
6090    -------------------------------------------------------------------------------------------
6091    -- 4262811 - Generate the Accrual Reversal lines
6092    -------------------------------------------------------------------------------------------
6093    BEGIN
6094       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
6095                               (g_array_event(p_event_id).array_value_num('header_index'));
6096       IF l_acc_rev_flag IS NULL THEN
6097          l_acc_rev_flag := 'N';
6098       END IF;
6099    EXCEPTION
6100       WHEN OTHERS THEN
6101          l_acc_rev_flag := 'N';
6102    END;
6103    --
6104    IF (l_acc_rev_flag = 'Y') THEN
6105 
6106        -- 4645092  ------------------------------------------------------------------------------
6107        -- To allow MPA report to determine if it should generate report process
6108        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
6109        ------------------------------------------------------------------------------------------
6110 
6111        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
6112        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
6113 
6114        --
6115        -- Update the line information that should be overwritten
6116        --
6117        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
6118                                          p_header_num   => 1);
6119        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
6120 
6121        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
6122 
6123        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
6124           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
6125        END IF;
6126 
6127       --
6128       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
6129       --
6130       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
6131           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
6132       ELSE
6133           ---------------------------------------------------------------------------------------------------
6134           -- 4262811a Switch Sign
6135           ---------------------------------------------------------------------------------------------------
6136           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
6137           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
6138                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
6139           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
6140                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
6141           -- 5132302
6142           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
6146 
6143                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
6144 
6145       END IF;
6147       -- 4955764
6148       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
6149       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
6150 
6151 
6152       XLA_AE_LINES_PKG.ValidateCurrentLine;
6153       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
6154 
6155       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
6156                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
6157                ,p_balance_type_code => l_balance_type_code);
6158 
6159    END IF;
6160 
6161    -----------------------------------------------------------------------------------------
6162    -- 4262811 Multiperiod Accounting
6163    -----------------------------------------------------------------------------------------
6164      -- No MPA option is assigned.
6165 
6166 
6167 END IF;
6168 END IF;
6169 --
6170 
6171 --
6172 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
6173    trace
6174       (p_msg      => 'END of AcctLineType_14'
6175       ,p_level    => C_LEVEL_PROCEDURE
6176       ,p_module   => l_log_module);
6177 END IF;
6178 --
6179 EXCEPTION
6180   WHEN xla_exceptions_pkg.application_exception THEN
6181       RAISE;
6182   WHEN OTHERS THEN
6183        xla_exceptions_pkg.raise_message
6184            (p_location => 'XLA_08407_AAD_S_000013_BC_PKG.AcctLineType_14');
6185 END AcctLineType_14;
6186 --
6187 
6188 ---------------------------------------
6189 --
6190 -- PRIVATE FUNCTION
6191 --         AcctLineType_15
6192 --
6193 ---------------------------------------
6194 PROCEDURE AcctLineType_15 (
6195   p_application_id        IN NUMBER
6196  ,p_event_id              IN NUMBER
6197  ,p_calculate_acctd_flag  IN VARCHAR2
6198  ,p_calculate_g_l_flag    IN VARCHAR2
6199  ,p_actual_flag           IN OUT VARCHAR2
6200  ,p_balance_type_code     OUT VARCHAR2
6201  ,p_gain_or_loss_ref      OUT VARCHAR2
6202  
6203 --TRANSACTION DESCRIPTION
6204  , p_source_1            IN VARCHAR2
6205 --CODE COMBINATION ID
6206  , p_source_5            IN NUMBER
6207 --CC ACCT LINE ID
6208  , p_source_8            IN NUMBER
6209 --DOCUMENT TYPE
6210  , p_source_9            IN VARCHAR2
6211 --CC FUNC AMT
6212  , p_source_10            IN NUMBER
6213 --CURRENCY CODE
6214  , p_source_11            IN VARCHAR2
6215 --CC FUNC DR AMT
6216  , p_source_12            IN NUMBER
6217 )
6218 IS
6219 
6220 l_component_type              VARCHAR2(80);
6221 l_component_code              VARCHAR2(30);
6222 l_component_type_code         VARCHAR2(1);
6223 l_component_appl_id           INTEGER;
6224 l_amb_context_code            VARCHAR2(30);
6225 l_entity_code                 VARCHAR2(30);
6226 l_event_class_code            VARCHAR2(30);
6227 l_ae_header_id                NUMBER;
6228 l_event_type_code             VARCHAR2(30);
6229 l_line_definition_code        VARCHAR2(30);
6230 l_line_definition_owner_code  VARCHAR2(1);
6231 --
6232 -- adr variables
6233 l_segment                     VARCHAR2(30);
6234 l_ccid                        NUMBER;
6235 l_adr_transaction_coa_id      NUMBER;
6236 l_adr_accounting_coa_id       NUMBER;
6237 l_adr_flexfield_segment_code  VARCHAR2(30);
6238 l_adr_flex_value_set_id       NUMBER;
6239 l_adr_value_type_code         VARCHAR2(30);
6240 l_adr_value_combination_id    NUMBER;
6241 l_adr_value_segment_code      VARCHAR2(30);
6242 
6243 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
6244 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
6245 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
6246 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
6247 
6248 -- 4262811 Variables ------------------------------------------------------------------------------------------
6249 l_entered_amt_idx             NUMBER;
6250 l_accted_amt_idx              NUMBER;
6251 l_acc_rev_flag                VARCHAR2(1);
6252 l_accrual_line_num            NUMBER;
6253 l_tmp_amt                     NUMBER;
6254 l_acc_rev_natural_side_code   VARCHAR2(1);
6255 
6256 l_num_entries                 NUMBER;
6257 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
6258 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
6259 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
6260 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
6261 l_recog_line_1                NUMBER;
6262 l_recog_line_2                NUMBER;
6263 
6264 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
6265 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
6266 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
6267 
6268 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
6269 
6270 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
6271 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
6272 
6273 ---------------------------------------------------------------------------------------------------------------
6274 
6275 
6276 --
6280 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
6277 -- bulk performance
6278 --
6279 l_balance_type_code           VARCHAR2(1);
6281 l_log_module                  VARCHAR2(240);
6282 
6283 --
6284 -- Upgrade strategy
6285 --
6286 l_actual_upg_option           VARCHAR2(1);
6287 l_enc_upg_option           VARCHAR2(1);
6288 
6289 --
6290 BEGIN
6291 --
6292 IF g_log_enabled THEN
6293       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_15';
6294 END IF;
6295 --
6296 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
6297 
6298       trace
6299          (p_msg      => 'BEGIN of AcctLineType_15'
6300          ,p_level    => C_LEVEL_PROCEDURE
6301          ,p_module   => l_log_module);
6302 
6303 END IF;
6304 --
6305 l_component_type             := 'AMB_JLT';
6306 l_component_code             := 'CC_PURCHASE_ORDER_DR';
6307 l_component_type_code        := 'S';
6308 l_component_appl_id          :=  8407;
6309 l_amb_context_code           := 'DEFAULT';
6310 l_entity_code                := 'CC_PURCHASE_ORDERS';
6311 l_event_class_code           := 'CC_PURCHASE_ORDERS';
6312 l_event_type_code            := 'CC_PURCHASE_ORDERS_ALL';
6313 l_line_definition_owner_code := 'S';
6314 l_line_definition_code       := 'CC_PURCHASE_ORDER_CMN';
6315 --
6316 l_balance_type_code          := 'E';
6317 l_segment                     := NULL;
6318 l_ccid                        := NULL;
6319 l_adr_transaction_coa_id      := NULL;
6320 l_adr_accounting_coa_id       := NULL;
6321 l_adr_flexfield_segment_code  := NULL;
6322 l_adr_flex_value_set_id       := NULL;
6323 l_adr_value_type_code         := NULL;
6324 l_adr_value_combination_id    := NULL;
6325 l_adr_value_segment_code      := NULL;
6326 
6327 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
6328 l_bflow_class_code           := '';    -- 4219869 Business Flow
6329 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
6330 l_budgetary_control_flag     := 'Y';
6331 
6332 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
6333 l_bflow_applied_to_amt       := NULL; -- 5132302
6334 l_entered_amt_idx            := NULL;          -- 4262811
6335 l_accted_amt_idx             := NULL;          -- 4262811
6336 l_acc_rev_flag               := NULL;          -- 4262811
6337 l_accrual_line_num           := NULL;          -- 4262811
6338 l_tmp_amt                    := NULL;          -- 4262811
6339 --
6340  
6341 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
6342     l_balance_type_code <> 'B' THEN
6343 IF p_source_12 IS NOT NULL 
6344  THEN 
6345 
6346    --
6347    XLA_AE_LINES_PKG.SetNewLine;
6348 
6349    p_balance_type_code          := l_balance_type_code;
6350    -- set the flag so later we will know whether the gain loss line needs to be created
6351    
6352    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
6353      p_actual_flag :='A';
6354    END IF;
6355 
6356    --
6357    -- bulk performance
6358    --
6359    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
6360                                       p_header_num   => 0); -- 4262811
6361    --
6362    -- set accounting line options
6363    --
6364    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
6365            p_natural_side_code          => 'D'
6366          , p_gain_or_loss_flag          => 'N'
6367          , p_gl_transfer_mode_code      => 'D'
6368          , p_acct_entry_type_code       => 'E'
6369          , p_switch_side_flag           => 'N'
6370          , p_merge_duplicate_code       => 'N'
6371          );
6372    --
6373    l_acc_rev_natural_side_code := 'C';  -- 4262811
6374    -- 
6375    --
6376    -- set accounting line type info
6377    --
6378    xla_ae_lines_pkg.SetAcctLineType
6379       (p_component_type             => l_component_type
6380       ,p_event_type_code            => l_event_type_code
6381       ,p_line_definition_owner_code => l_line_definition_owner_code
6382       ,p_line_definition_code       => l_line_definition_code
6383       ,p_accounting_line_code       => l_component_code
6384       ,p_accounting_line_type_code  => l_component_type_code
6385       ,p_accounting_line_appl_id    => l_component_appl_id
6386       ,p_amb_context_code           => l_amb_context_code
6387       ,p_entity_code                => l_entity_code
6388       ,p_event_class_code           => l_event_class_code);
6389    --
6390    -- set accounting class
6391    --
6392    xla_ae_lines_pkg.SetAcctClass(
6393            p_accounting_class_code  => 'PURCHASE_ORDER'
6394          , p_ae_header_id           => l_ae_header_id
6395          );
6396 
6397    --
6398    -- set rounding class
6399    --
6400    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
6401                       'PURCHASE_ORDER';
6402 
6403    --
6404    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
6405    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
6406    --
6407    -- bulk performance
6408    --
6409    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
6410 
6411    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
6412       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
6413 
6414    -- 4955764
6418    -- 4458381 Public Sector Enh
6415    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
6416       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
6417 
6419       XLA_AE_LINES_PKG.g_rec_lines.array_encumbrance_type_id(XLA_AE_LINES_PKG.g_LineNumber) := 1001;
6420    --
6421    -- set accounting attributes for the line type
6422    --
6423    l_entered_amt_idx := 3;
6424    l_accted_amt_idx  := 5;
6425    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
6426    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
6427    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_8);
6428    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
6429    l_rec_acct_attrs.array_char_value(2)  := p_source_9;
6430    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
6431    l_rec_acct_attrs.array_num_value(3)  := p_source_10;
6432    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
6433    l_rec_acct_attrs.array_char_value(4)  := p_source_11;
6434    l_rec_acct_attrs.array_acct_attr_code(5) := 'LEDGER_AMOUNT';
6435    l_rec_acct_attrs.array_num_value(5)  := p_source_10;
6436 
6437    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
6438    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
6439 
6440    ---------------------------------------------------------------------------------------------------------------
6441    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
6442    ---------------------------------------------------------------------------------------------------------------
6443    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
6444 
6445    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
6446    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
6447 
6448    IF xla_accounting_cache_pkg.GetValueChar
6449          (p_source_code         => 'LEDGER_CATEGORY_CODE'
6450          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
6451    AND l_bflow_method_code = 'PRIOR_ENTRY'
6452 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
6453    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
6454          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
6455        )
6456    THEN
6457          xla_ae_lines_pkg.BflowUpgEntry
6458            (p_business_method_code    => l_bflow_method_code
6459            ,p_business_class_code     => l_bflow_class_code
6460            ,p_balance_type            => l_balance_type_code);
6461    ELSE
6462       NULL;
6463 -- No business flow processing for business flow method of NONE.
6464    END IF;
6465 
6466    --
6467    -- call analytical criteria
6468    --
6469    
6470    --
6471    -- call description
6472    --
6473    
6474 xla_ae_lines_pkg.SetLineDescription(
6475    p_ae_header_id => l_ae_header_id
6476   ,p_description  => Description_1 (
6477      p_application_id         => p_application_id
6478    , p_ae_header_id           => l_ae_header_id 
6479 , p_source_1 => p_source_1
6480    )
6481 );
6482 
6483 
6484    --
6485    -- call ADRs
6486    -- Bug 4922099
6487    --
6488    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
6489         (NVL(l_actual_upg_option, 'N') = 'O') OR
6490         (NVL(l_enc_upg_option, 'N') = 'O')
6491       )
6492    THEN
6493    NULL;
6494    --
6495    --
6496    
6497   l_ccid := AcctDerRule_3(
6498            p_application_id           => p_application_id
6499          , p_ae_header_id             => l_ae_header_id 
6500 , p_source_5 => p_source_5
6501          , x_transaction_coa_id       => l_adr_transaction_coa_id
6502          , x_accounting_coa_id        => l_adr_accounting_coa_id
6503          , x_value_type_code          => l_adr_value_type_code
6504          , p_side                     => 'NA'
6505    );
6506 
6507    xla_ae_lines_pkg.set_ccid(
6508     p_code_combination_id          => l_ccid
6509   , p_value_type_code              => l_adr_value_type_code
6510   , p_transaction_coa_id           => l_adr_transaction_coa_id
6511   , p_accounting_coa_id            => l_adr_accounting_coa_id
6512   , p_adr_code                     => 'CC_COMMON_ADR'
6513   , p_adr_type_code                => 'S'
6514   , p_component_type               => l_component_type
6515   , p_component_code               => l_component_code
6516   , p_component_type_code          => l_component_type_code
6517   , p_component_appl_id            => l_component_appl_id
6518   , p_amb_context_code             => l_amb_context_code
6519   , p_side                         => 'NA'
6520   );
6521 
6522 
6523    --
6524    --
6525    END IF;
6526    --
6527    -- Bug 4922099
6528    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
6529           (NVL(l_enc_upg_option, 'N') = 'O')
6530         ) AND
6531         (l_bflow_method_code = 'PRIOR_ENTRY')
6532       )
6533    THEN
6534       IF
6535       --
6536       1 = 2
6537       --
6538       THEN
6539       xla_accounting_err_pkg.build_message
6540                                     (p_appli_s_name            => 'XLA'
6544                                     ,p_token_2                 => 'LINE_TYPE_NAME'
6541                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
6542                                     ,p_token_1                 => 'LINE_NUMBER'
6543                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
6545                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
6546                                                                              l_component_type
6547                                                                             ,l_component_code
6548                                                                             ,l_component_type_code
6549                                                                             ,l_component_appl_id
6550                                                                             ,l_amb_context_code
6551                                                                             ,l_entity_code
6552                                                                             ,l_event_class_code
6553                                                                            )
6554                                     ,p_token_3                 => 'OWNER'
6555                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
6556                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
6557                                                                           ,p_lookup_code    => l_component_type_code
6558                                                                          )
6559                                     ,p_token_4                 => 'PRODUCT_NAME'
6560                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
6561                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
6562                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
6563                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
6564                                     ,p_ae_header_id            =>  NULL
6565                                        );
6566 
6567         IF (C_LEVEL_ERROR>= g_log_level) THEN
6568                  trace
6569                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
6570                       ,p_level    => C_LEVEL_ERROR
6571                       ,p_module   => l_log_module);
6572         END IF;
6573       END IF;
6574    END IF;
6575    --
6576    --
6577    ------------------------------------------------------------------------------------------------
6578    -- 4219869 Business Flow
6579    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
6580    -- Prior Entry.  Currently, the following code is always generated.
6581    ------------------------------------------------------------------------------------------------
6582    XLA_AE_LINES_PKG.ValidateCurrentLine;
6583 
6584    ------------------------------------------------------------------------------------
6585    -- 4219869 Business Flow
6586    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
6587    ------------------------------------------------------------------------------------
6588    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
6589 
6590    ----------------------------------------------------------------------------------
6591    -- 4219869 Business Flow
6592    -- Update journal entry status -- Need to generate this within IF <condition>
6593    ----------------------------------------------------------------------------------
6594    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
6595          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
6596          ,p_balance_type_code => l_balance_type_code
6597          );
6598 
6599    -------------------------------------------------------------------------------------------
6600    -- 4262811 - Generate the Accrual Reversal lines
6601    -------------------------------------------------------------------------------------------
6602    BEGIN
6603       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
6604                               (g_array_event(p_event_id).array_value_num('header_index'));
6605       IF l_acc_rev_flag IS NULL THEN
6606          l_acc_rev_flag := 'N';
6607       END IF;
6608    EXCEPTION
6609       WHEN OTHERS THEN
6610          l_acc_rev_flag := 'N';
6611    END;
6612    --
6613    IF (l_acc_rev_flag = 'Y') THEN
6614 
6615        -- 4645092  ------------------------------------------------------------------------------
6616        -- To allow MPA report to determine if it should generate report process
6617        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
6618        ------------------------------------------------------------------------------------------
6619 
6620        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
6621        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
6622 
6623        --
6624        -- Update the line information that should be overwritten
6625        --
6626        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
6627                                          p_header_num   => 1);
6628        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
6629 
6633           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
6630        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
6631 
6632        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
6634        END IF;
6635 
6636       --
6637       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
6638       --
6639       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
6640           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
6641       ELSE
6642           ---------------------------------------------------------------------------------------------------
6643           -- 4262811a Switch Sign
6644           ---------------------------------------------------------------------------------------------------
6645           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
6646           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
6647                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
6648           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
6649                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
6650           -- 5132302
6651           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
6652                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
6653 
6654       END IF;
6655 
6656       -- 4955764
6657       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
6658       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
6659 
6660 
6661       XLA_AE_LINES_PKG.ValidateCurrentLine;
6662       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
6663 
6664       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
6665                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
6666                ,p_balance_type_code => l_balance_type_code);
6667 
6668    END IF;
6669 
6670    -----------------------------------------------------------------------------------------
6671    -- 4262811 Multiperiod Accounting
6672    -----------------------------------------------------------------------------------------
6673      -- No MPA option is assigned.
6674 
6675 
6676 END IF;
6677 END IF;
6678 --
6679 
6680 --
6681 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
6682    trace
6683       (p_msg      => 'END of AcctLineType_15'
6684       ,p_level    => C_LEVEL_PROCEDURE
6685       ,p_module   => l_log_module);
6686 END IF;
6687 --
6688 EXCEPTION
6689   WHEN xla_exceptions_pkg.application_exception THEN
6690       RAISE;
6691   WHEN OTHERS THEN
6692        xla_exceptions_pkg.raise_message
6693            (p_location => 'XLA_08407_AAD_S_000013_BC_PKG.AcctLineType_15');
6694 END AcctLineType_15;
6695 --
6696 
6697 ---------------------------------------
6698 --
6699 -- PRIVATE FUNCTION
6700 --         AcctLineType_16
6701 --
6702 ---------------------------------------
6703 PROCEDURE AcctLineType_16 (
6704   p_application_id        IN NUMBER
6705  ,p_event_id              IN NUMBER
6706  ,p_calculate_acctd_flag  IN VARCHAR2
6707  ,p_calculate_g_l_flag    IN VARCHAR2
6708  ,p_actual_flag           IN OUT VARCHAR2
6709  ,p_balance_type_code     OUT VARCHAR2
6710  ,p_gain_or_loss_ref      OUT VARCHAR2
6711  
6712 --TRANSACTION DESCRIPTION
6713  , p_source_1            IN VARCHAR2
6714 --CODE COMBINATION ID
6715  , p_source_5            IN NUMBER
6716 --CC FUNC CR AMT
6717  , p_source_6            IN NUMBER
6718 --CC ACCT LINE ID
6719  , p_source_8            IN NUMBER
6720 --DOCUMENT TYPE
6721  , p_source_9            IN VARCHAR2
6722 --CC FUNC AMT
6723  , p_source_10            IN NUMBER
6724 --CURRENCY CODE
6725  , p_source_11            IN VARCHAR2
6726 )
6727 IS
6728 
6729 l_component_type              VARCHAR2(80);
6730 l_component_code              VARCHAR2(30);
6731 l_component_type_code         VARCHAR2(1);
6732 l_component_appl_id           INTEGER;
6733 l_amb_context_code            VARCHAR2(30);
6734 l_entity_code                 VARCHAR2(30);
6735 l_event_class_code            VARCHAR2(30);
6736 l_ae_header_id                NUMBER;
6737 l_event_type_code             VARCHAR2(30);
6738 l_line_definition_code        VARCHAR2(30);
6739 l_line_definition_owner_code  VARCHAR2(1);
6740 --
6741 -- adr variables
6742 l_segment                     VARCHAR2(30);
6743 l_ccid                        NUMBER;
6744 l_adr_transaction_coa_id      NUMBER;
6745 l_adr_accounting_coa_id       NUMBER;
6746 l_adr_flexfield_segment_code  VARCHAR2(30);
6747 l_adr_flex_value_set_id       NUMBER;
6748 l_adr_value_type_code         VARCHAR2(30);
6749 l_adr_value_combination_id    NUMBER;
6750 l_adr_value_segment_code      VARCHAR2(30);
6751 
6752 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
6753 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
6754 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
6758 l_entered_amt_idx             NUMBER;
6755 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
6756 
6757 -- 4262811 Variables ------------------------------------------------------------------------------------------
6759 l_accted_amt_idx              NUMBER;
6760 l_acc_rev_flag                VARCHAR2(1);
6761 l_accrual_line_num            NUMBER;
6762 l_tmp_amt                     NUMBER;
6763 l_acc_rev_natural_side_code   VARCHAR2(1);
6764 
6765 l_num_entries                 NUMBER;
6766 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
6767 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
6768 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
6769 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
6770 l_recog_line_1                NUMBER;
6771 l_recog_line_2                NUMBER;
6772 
6773 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
6774 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
6775 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
6776 
6777 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
6778 
6779 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
6780 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
6781 
6782 ---------------------------------------------------------------------------------------------------------------
6783 
6784 
6785 --
6786 -- bulk performance
6787 --
6788 l_balance_type_code           VARCHAR2(1);
6789 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
6790 l_log_module                  VARCHAR2(240);
6791 
6792 --
6793 -- Upgrade strategy
6794 --
6795 l_actual_upg_option           VARCHAR2(1);
6796 l_enc_upg_option           VARCHAR2(1);
6797 
6798 --
6799 BEGIN
6800 --
6801 IF g_log_enabled THEN
6802       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_16';
6803 END IF;
6804 --
6805 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
6806 
6807       trace
6808          (p_msg      => 'BEGIN of AcctLineType_16'
6809          ,p_level    => C_LEVEL_PROCEDURE
6810          ,p_module   => l_log_module);
6811 
6812 END IF;
6813 --
6814 l_component_type             := 'AMB_JLT';
6815 l_component_code             := 'CC_REQUISITION_CR';
6816 l_component_type_code        := 'S';
6817 l_component_appl_id          :=  8407;
6818 l_amb_context_code           := 'DEFAULT';
6819 l_entity_code                := 'CC_REQUISITIONS';
6820 l_event_class_code           := 'CC_REQUISITIONS';
6821 l_event_type_code            := 'CC_REQUISITIONS_ALL';
6822 l_line_definition_owner_code := 'S';
6823 l_line_definition_code       := 'CC_REQUISITION_CMN';
6824 --
6825 l_balance_type_code          := 'E';
6826 l_segment                     := NULL;
6827 l_ccid                        := NULL;
6828 l_adr_transaction_coa_id      := NULL;
6829 l_adr_accounting_coa_id       := NULL;
6830 l_adr_flexfield_segment_code  := NULL;
6831 l_adr_flex_value_set_id       := NULL;
6832 l_adr_value_type_code         := NULL;
6833 l_adr_value_combination_id    := NULL;
6834 l_adr_value_segment_code      := NULL;
6835 
6836 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
6837 l_bflow_class_code           := '';    -- 4219869 Business Flow
6838 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
6839 l_budgetary_control_flag     := 'Y';
6840 
6841 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
6842 l_bflow_applied_to_amt       := NULL; -- 5132302
6843 l_entered_amt_idx            := NULL;          -- 4262811
6844 l_accted_amt_idx             := NULL;          -- 4262811
6845 l_acc_rev_flag               := NULL;          -- 4262811
6846 l_accrual_line_num           := NULL;          -- 4262811
6847 l_tmp_amt                    := NULL;          -- 4262811
6848 --
6849  
6850 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
6851     l_balance_type_code <> 'B' THEN
6852 IF p_source_6 IS NOT NULL 
6853  THEN 
6854 
6855    --
6856    XLA_AE_LINES_PKG.SetNewLine;
6857 
6858    p_balance_type_code          := l_balance_type_code;
6859    -- set the flag so later we will know whether the gain loss line needs to be created
6860    
6861    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
6862      p_actual_flag :='A';
6863    END IF;
6864 
6865    --
6866    -- bulk performance
6867    --
6868    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
6869                                       p_header_num   => 0); -- 4262811
6870    --
6871    -- set accounting line options
6872    --
6873    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
6874            p_natural_side_code          => 'C'
6875          , p_gain_or_loss_flag          => 'N'
6876          , p_gl_transfer_mode_code      => 'D'
6877          , p_acct_entry_type_code       => 'E'
6878          , p_switch_side_flag           => 'N'
6879          , p_merge_duplicate_code       => 'N'
6880          );
6881    --
6882    l_acc_rev_natural_side_code := 'D';  -- 4262811
6883    -- 
6884    --
6885    -- set accounting line type info
6886    --
6887    xla_ae_lines_pkg.SetAcctLineType
6888       (p_component_type             => l_component_type
6889       ,p_event_type_code            => l_event_type_code
6893       ,p_accounting_line_type_code  => l_component_type_code
6890       ,p_line_definition_owner_code => l_line_definition_owner_code
6891       ,p_line_definition_code       => l_line_definition_code
6892       ,p_accounting_line_code       => l_component_code
6894       ,p_accounting_line_appl_id    => l_component_appl_id
6895       ,p_amb_context_code           => l_amb_context_code
6896       ,p_entity_code                => l_entity_code
6897       ,p_event_class_code           => l_event_class_code);
6898    --
6899    -- set accounting class
6900    --
6901    xla_ae_lines_pkg.SetAcctClass(
6902            p_accounting_class_code  => 'REQUISITION'
6903          , p_ae_header_id           => l_ae_header_id
6904          );
6905 
6906    --
6907    -- set rounding class
6908    --
6909    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
6910                       'REQUISITION';
6911 
6912    --
6913    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
6914    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
6915    --
6916    -- bulk performance
6917    --
6918    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
6919 
6920    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
6921       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
6922 
6923    -- 4955764
6924    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
6925       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
6926 
6927    -- 4458381 Public Sector Enh
6928       XLA_AE_LINES_PKG.g_rec_lines.array_encumbrance_type_id(XLA_AE_LINES_PKG.g_LineNumber) := 1000;
6929    --
6930    -- set accounting attributes for the line type
6931    --
6932    l_entered_amt_idx := 3;
6933    l_accted_amt_idx  := 5;
6934    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
6935    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
6936    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_8);
6937    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
6938    l_rec_acct_attrs.array_char_value(2)  := p_source_9;
6939    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
6940    l_rec_acct_attrs.array_num_value(3)  := p_source_10;
6941    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
6942    l_rec_acct_attrs.array_char_value(4)  := p_source_11;
6943    l_rec_acct_attrs.array_acct_attr_code(5) := 'LEDGER_AMOUNT';
6944    l_rec_acct_attrs.array_num_value(5)  := p_source_10;
6945 
6946    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
6947    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
6948 
6949    ---------------------------------------------------------------------------------------------------------------
6950    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
6951    ---------------------------------------------------------------------------------------------------------------
6952    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
6953 
6954    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
6955    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
6956 
6957    IF xla_accounting_cache_pkg.GetValueChar
6958          (p_source_code         => 'LEDGER_CATEGORY_CODE'
6959          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
6960    AND l_bflow_method_code = 'PRIOR_ENTRY'
6961 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
6962    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
6963          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
6964        )
6965    THEN
6966          xla_ae_lines_pkg.BflowUpgEntry
6967            (p_business_method_code    => l_bflow_method_code
6968            ,p_business_class_code     => l_bflow_class_code
6969            ,p_balance_type            => l_balance_type_code);
6970    ELSE
6971       NULL;
6972 -- No business flow processing for business flow method of NONE.
6973    END IF;
6974 
6975    --
6976    -- call analytical criteria
6977    --
6978    
6979    --
6980    -- call description
6981    --
6982    
6983 xla_ae_lines_pkg.SetLineDescription(
6984    p_ae_header_id => l_ae_header_id
6985   ,p_description  => Description_1 (
6986      p_application_id         => p_application_id
6987    , p_ae_header_id           => l_ae_header_id 
6988 , p_source_1 => p_source_1
6989    )
6990 );
6991 
6992 
6993    --
6994    -- call ADRs
6995    -- Bug 4922099
6996    --
6997    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
6998         (NVL(l_actual_upg_option, 'N') = 'O') OR
6999         (NVL(l_enc_upg_option, 'N') = 'O')
7000       )
7001    THEN
7002    NULL;
7003    --
7004    --
7005    
7006   l_ccid := AcctDerRule_3(
7007            p_application_id           => p_application_id
7008          , p_ae_header_id             => l_ae_header_id 
7009 , p_source_5 => p_source_5
7010          , x_transaction_coa_id       => l_adr_transaction_coa_id
7014    );
7011          , x_accounting_coa_id        => l_adr_accounting_coa_id
7012          , x_value_type_code          => l_adr_value_type_code
7013          , p_side                     => 'NA'
7015 
7016    xla_ae_lines_pkg.set_ccid(
7017     p_code_combination_id          => l_ccid
7018   , p_value_type_code              => l_adr_value_type_code
7019   , p_transaction_coa_id           => l_adr_transaction_coa_id
7020   , p_accounting_coa_id            => l_adr_accounting_coa_id
7021   , p_adr_code                     => 'CC_COMMON_ADR'
7022   , p_adr_type_code                => 'S'
7023   , p_component_type               => l_component_type
7024   , p_component_code               => l_component_code
7025   , p_component_type_code          => l_component_type_code
7026   , p_component_appl_id            => l_component_appl_id
7027   , p_amb_context_code             => l_amb_context_code
7028   , p_side                         => 'NA'
7029   );
7030 
7031 
7032    --
7033    --
7034    END IF;
7035    --
7036    -- Bug 4922099
7037    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
7038           (NVL(l_enc_upg_option, 'N') = 'O')
7039         ) AND
7040         (l_bflow_method_code = 'PRIOR_ENTRY')
7041       )
7042    THEN
7043       IF
7044       --
7045       1 = 2
7046       --
7047       THEN
7048       xla_accounting_err_pkg.build_message
7049                                     (p_appli_s_name            => 'XLA'
7050                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
7051                                     ,p_token_1                 => 'LINE_NUMBER'
7052                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
7053                                     ,p_token_2                 => 'LINE_TYPE_NAME'
7054                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
7055                                                                              l_component_type
7056                                                                             ,l_component_code
7057                                                                             ,l_component_type_code
7058                                                                             ,l_component_appl_id
7059                                                                             ,l_amb_context_code
7060                                                                             ,l_entity_code
7061                                                                             ,l_event_class_code
7062                                                                            )
7063                                     ,p_token_3                 => 'OWNER'
7064                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
7065                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
7066                                                                           ,p_lookup_code    => l_component_type_code
7067                                                                          )
7068                                     ,p_token_4                 => 'PRODUCT_NAME'
7069                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
7070                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
7071                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
7072                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
7073                                     ,p_ae_header_id            =>  NULL
7074                                        );
7075 
7076         IF (C_LEVEL_ERROR>= g_log_level) THEN
7077                  trace
7078                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
7079                       ,p_level    => C_LEVEL_ERROR
7080                       ,p_module   => l_log_module);
7081         END IF;
7082       END IF;
7083    END IF;
7084    --
7085    --
7086    ------------------------------------------------------------------------------------------------
7087    -- 4219869 Business Flow
7088    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
7089    -- Prior Entry.  Currently, the following code is always generated.
7090    ------------------------------------------------------------------------------------------------
7091    XLA_AE_LINES_PKG.ValidateCurrentLine;
7092 
7093    ------------------------------------------------------------------------------------
7094    -- 4219869 Business Flow
7095    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
7096    ------------------------------------------------------------------------------------
7097    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
7098 
7099    ----------------------------------------------------------------------------------
7100    -- 4219869 Business Flow
7101    -- Update journal entry status -- Need to generate this within IF <condition>
7102    ----------------------------------------------------------------------------------
7103    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
7104          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
7105          ,p_balance_type_code => l_balance_type_code
7106          );
7107 
7108    -------------------------------------------------------------------------------------------
7112       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
7109    -- 4262811 - Generate the Accrual Reversal lines
7110    -------------------------------------------------------------------------------------------
7111    BEGIN
7113                               (g_array_event(p_event_id).array_value_num('header_index'));
7114       IF l_acc_rev_flag IS NULL THEN
7115          l_acc_rev_flag := 'N';
7116       END IF;
7117    EXCEPTION
7118       WHEN OTHERS THEN
7119          l_acc_rev_flag := 'N';
7120    END;
7121    --
7122    IF (l_acc_rev_flag = 'Y') THEN
7123 
7124        -- 4645092  ------------------------------------------------------------------------------
7125        -- To allow MPA report to determine if it should generate report process
7126        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
7127        ------------------------------------------------------------------------------------------
7128 
7129        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
7130        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
7131 
7132        --
7133        -- Update the line information that should be overwritten
7134        --
7135        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
7136                                          p_header_num   => 1);
7137        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
7138 
7139        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
7140 
7141        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
7142           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
7143        END IF;
7144 
7145       --
7146       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
7147       --
7148       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
7149           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
7150       ELSE
7151           ---------------------------------------------------------------------------------------------------
7152           -- 4262811a Switch Sign
7153           ---------------------------------------------------------------------------------------------------
7154           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
7155           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
7156                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
7157           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
7158                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
7159           -- 5132302
7160           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
7161                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
7162 
7163       END IF;
7164 
7165       -- 4955764
7166       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
7167       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
7168 
7169 
7170       XLA_AE_LINES_PKG.ValidateCurrentLine;
7171       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
7172 
7173       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
7174                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
7175                ,p_balance_type_code => l_balance_type_code);
7176 
7177    END IF;
7178 
7179    -----------------------------------------------------------------------------------------
7180    -- 4262811 Multiperiod Accounting
7181    -----------------------------------------------------------------------------------------
7182      -- No MPA option is assigned.
7183 
7184 
7185 END IF;
7186 END IF;
7187 --
7188 
7189 --
7190 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
7191    trace
7192       (p_msg      => 'END of AcctLineType_16'
7193       ,p_level    => C_LEVEL_PROCEDURE
7194       ,p_module   => l_log_module);
7195 END IF;
7196 --
7197 EXCEPTION
7198   WHEN xla_exceptions_pkg.application_exception THEN
7199       RAISE;
7200   WHEN OTHERS THEN
7201        xla_exceptions_pkg.raise_message
7202            (p_location => 'XLA_08407_AAD_S_000013_BC_PKG.AcctLineType_16');
7203 END AcctLineType_16;
7204 --
7205 
7206 ---------------------------------------
7207 --
7208 -- PRIVATE FUNCTION
7209 --         AcctLineType_17
7210 --
7211 ---------------------------------------
7212 PROCEDURE AcctLineType_17 (
7213   p_application_id        IN NUMBER
7214  ,p_event_id              IN NUMBER
7215  ,p_calculate_acctd_flag  IN VARCHAR2
7216  ,p_calculate_g_l_flag    IN VARCHAR2
7217  ,p_actual_flag           IN OUT VARCHAR2
7218  ,p_balance_type_code     OUT VARCHAR2
7219  ,p_gain_or_loss_ref      OUT VARCHAR2
7220  
7221 --TRANSACTION DESCRIPTION
7222  , p_source_1            IN VARCHAR2
7223 --CODE COMBINATION ID
7224  , p_source_5            IN NUMBER
7225 --CC ACCT LINE ID
7226  , p_source_8            IN NUMBER
7227 --DOCUMENT TYPE
7228  , p_source_9            IN VARCHAR2
7229 --CC FUNC AMT
7233 --CC FUNC DR AMT
7230  , p_source_10            IN NUMBER
7231 --CURRENCY CODE
7232  , p_source_11            IN VARCHAR2
7234  , p_source_12            IN NUMBER
7235 )
7236 IS
7237 
7238 l_component_type              VARCHAR2(80);
7239 l_component_code              VARCHAR2(30);
7240 l_component_type_code         VARCHAR2(1);
7241 l_component_appl_id           INTEGER;
7242 l_amb_context_code            VARCHAR2(30);
7243 l_entity_code                 VARCHAR2(30);
7244 l_event_class_code            VARCHAR2(30);
7245 l_ae_header_id                NUMBER;
7246 l_event_type_code             VARCHAR2(30);
7247 l_line_definition_code        VARCHAR2(30);
7248 l_line_definition_owner_code  VARCHAR2(1);
7249 --
7250 -- adr variables
7251 l_segment                     VARCHAR2(30);
7252 l_ccid                        NUMBER;
7253 l_adr_transaction_coa_id      NUMBER;
7254 l_adr_accounting_coa_id       NUMBER;
7255 l_adr_flexfield_segment_code  VARCHAR2(30);
7256 l_adr_flex_value_set_id       NUMBER;
7257 l_adr_value_type_code         VARCHAR2(30);
7258 l_adr_value_combination_id    NUMBER;
7259 l_adr_value_segment_code      VARCHAR2(30);
7260 
7261 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
7262 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
7263 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
7264 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
7265 
7266 -- 4262811 Variables ------------------------------------------------------------------------------------------
7267 l_entered_amt_idx             NUMBER;
7268 l_accted_amt_idx              NUMBER;
7269 l_acc_rev_flag                VARCHAR2(1);
7270 l_accrual_line_num            NUMBER;
7271 l_tmp_amt                     NUMBER;
7272 l_acc_rev_natural_side_code   VARCHAR2(1);
7273 
7274 l_num_entries                 NUMBER;
7275 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
7276 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
7277 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
7278 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
7279 l_recog_line_1                NUMBER;
7280 l_recog_line_2                NUMBER;
7281 
7282 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
7283 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
7284 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
7285 
7286 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
7287 
7288 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
7289 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
7290 
7291 ---------------------------------------------------------------------------------------------------------------
7292 
7293 
7294 --
7295 -- bulk performance
7296 --
7297 l_balance_type_code           VARCHAR2(1);
7298 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
7299 l_log_module                  VARCHAR2(240);
7300 
7301 --
7302 -- Upgrade strategy
7303 --
7304 l_actual_upg_option           VARCHAR2(1);
7305 l_enc_upg_option           VARCHAR2(1);
7306 
7307 --
7308 BEGIN
7309 --
7310 IF g_log_enabled THEN
7311       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_17';
7312 END IF;
7313 --
7314 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
7315 
7316       trace
7317          (p_msg      => 'BEGIN of AcctLineType_17'
7318          ,p_level    => C_LEVEL_PROCEDURE
7319          ,p_module   => l_log_module);
7320 
7321 END IF;
7322 --
7323 l_component_type             := 'AMB_JLT';
7324 l_component_code             := 'CC_REQUISITION_DR';
7325 l_component_type_code        := 'S';
7326 l_component_appl_id          :=  8407;
7327 l_amb_context_code           := 'DEFAULT';
7328 l_entity_code                := 'CC_REQUISITIONS';
7329 l_event_class_code           := 'CC_REQUISITIONS';
7330 l_event_type_code            := 'CC_REQUISITIONS_ALL';
7331 l_line_definition_owner_code := 'S';
7332 l_line_definition_code       := 'CC_REQUISITION_CMN';
7333 --
7334 l_balance_type_code          := 'E';
7335 l_segment                     := NULL;
7336 l_ccid                        := NULL;
7337 l_adr_transaction_coa_id      := NULL;
7338 l_adr_accounting_coa_id       := NULL;
7339 l_adr_flexfield_segment_code  := NULL;
7340 l_adr_flex_value_set_id       := NULL;
7341 l_adr_value_type_code         := NULL;
7342 l_adr_value_combination_id    := NULL;
7343 l_adr_value_segment_code      := NULL;
7344 
7345 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
7346 l_bflow_class_code           := '';    -- 4219869 Business Flow
7347 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
7348 l_budgetary_control_flag     := 'Y';
7349 
7350 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
7351 l_bflow_applied_to_amt       := NULL; -- 5132302
7352 l_entered_amt_idx            := NULL;          -- 4262811
7353 l_accted_amt_idx             := NULL;          -- 4262811
7354 l_acc_rev_flag               := NULL;          -- 4262811
7355 l_accrual_line_num           := NULL;          -- 4262811
7356 l_tmp_amt                    := NULL;          -- 4262811
7357 --
7358  
7359 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
7360     l_balance_type_code <> 'B' THEN
7364    --
7361 IF p_source_12 IS NOT NULL 
7362  THEN 
7363 
7365    XLA_AE_LINES_PKG.SetNewLine;
7366 
7367    p_balance_type_code          := l_balance_type_code;
7368    -- set the flag so later we will know whether the gain loss line needs to be created
7369    
7370    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
7371      p_actual_flag :='A';
7372    END IF;
7373 
7374    --
7375    -- bulk performance
7376    --
7377    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
7378                                       p_header_num   => 0); -- 4262811
7379    --
7380    -- set accounting line options
7381    --
7382    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
7383            p_natural_side_code          => 'D'
7384          , p_gain_or_loss_flag          => 'N'
7385          , p_gl_transfer_mode_code      => 'D'
7386          , p_acct_entry_type_code       => 'E'
7387          , p_switch_side_flag           => 'N'
7388          , p_merge_duplicate_code       => 'N'
7389          );
7390    --
7391    l_acc_rev_natural_side_code := 'C';  -- 4262811
7392    -- 
7393    --
7394    -- set accounting line type info
7395    --
7396    xla_ae_lines_pkg.SetAcctLineType
7397       (p_component_type             => l_component_type
7398       ,p_event_type_code            => l_event_type_code
7399       ,p_line_definition_owner_code => l_line_definition_owner_code
7400       ,p_line_definition_code       => l_line_definition_code
7401       ,p_accounting_line_code       => l_component_code
7402       ,p_accounting_line_type_code  => l_component_type_code
7403       ,p_accounting_line_appl_id    => l_component_appl_id
7404       ,p_amb_context_code           => l_amb_context_code
7405       ,p_entity_code                => l_entity_code
7406       ,p_event_class_code           => l_event_class_code);
7407    --
7408    -- set accounting class
7409    --
7410    xla_ae_lines_pkg.SetAcctClass(
7411            p_accounting_class_code  => 'REQUISITION'
7412          , p_ae_header_id           => l_ae_header_id
7413          );
7414 
7415    --
7416    -- set rounding class
7417    --
7418    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
7419                       'REQUISITION';
7420 
7421    --
7422    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
7423    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
7424    --
7425    -- bulk performance
7426    --
7427    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
7428 
7429    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
7430       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
7431 
7432    -- 4955764
7433    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
7434       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
7435 
7436    -- 4458381 Public Sector Enh
7437       XLA_AE_LINES_PKG.g_rec_lines.array_encumbrance_type_id(XLA_AE_LINES_PKG.g_LineNumber) := 1000;
7438    --
7439    -- set accounting attributes for the line type
7440    --
7441    l_entered_amt_idx := 3;
7442    l_accted_amt_idx  := 5;
7443    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
7444    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
7445    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_8);
7446    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
7447    l_rec_acct_attrs.array_char_value(2)  := p_source_9;
7448    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
7449    l_rec_acct_attrs.array_num_value(3)  := p_source_10;
7450    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
7451    l_rec_acct_attrs.array_char_value(4)  := p_source_11;
7452    l_rec_acct_attrs.array_acct_attr_code(5) := 'LEDGER_AMOUNT';
7453    l_rec_acct_attrs.array_num_value(5)  := p_source_10;
7454 
7455    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
7456    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
7457 
7458    ---------------------------------------------------------------------------------------------------------------
7459    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
7460    ---------------------------------------------------------------------------------------------------------------
7461    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
7462 
7463    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
7464    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
7465 
7466    IF xla_accounting_cache_pkg.GetValueChar
7467          (p_source_code         => 'LEDGER_CATEGORY_CODE'
7468          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
7469    AND l_bflow_method_code = 'PRIOR_ENTRY'
7470 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
7471    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
7472          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
7473        )
7474    THEN
7475          xla_ae_lines_pkg.BflowUpgEntry
7479    ELSE
7476            (p_business_method_code    => l_bflow_method_code
7477            ,p_business_class_code     => l_bflow_class_code
7478            ,p_balance_type            => l_balance_type_code);
7480       NULL;
7481 -- No business flow processing for business flow method of NONE.
7482    END IF;
7483 
7484    --
7485    -- call analytical criteria
7486    --
7487    
7488    --
7489    -- call description
7490    --
7491    
7492 xla_ae_lines_pkg.SetLineDescription(
7493    p_ae_header_id => l_ae_header_id
7494   ,p_description  => Description_1 (
7495      p_application_id         => p_application_id
7496    , p_ae_header_id           => l_ae_header_id 
7497 , p_source_1 => p_source_1
7498    )
7499 );
7500 
7501 
7502    --
7503    -- call ADRs
7504    -- Bug 4922099
7505    --
7506    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
7507         (NVL(l_actual_upg_option, 'N') = 'O') OR
7508         (NVL(l_enc_upg_option, 'N') = 'O')
7509       )
7510    THEN
7511    NULL;
7512    --
7513    --
7514    
7515   l_ccid := AcctDerRule_3(
7516            p_application_id           => p_application_id
7517          , p_ae_header_id             => l_ae_header_id 
7518 , p_source_5 => p_source_5
7519          , x_transaction_coa_id       => l_adr_transaction_coa_id
7520          , x_accounting_coa_id        => l_adr_accounting_coa_id
7521          , x_value_type_code          => l_adr_value_type_code
7522          , p_side                     => 'NA'
7523    );
7524 
7525    xla_ae_lines_pkg.set_ccid(
7526     p_code_combination_id          => l_ccid
7527   , p_value_type_code              => l_adr_value_type_code
7528   , p_transaction_coa_id           => l_adr_transaction_coa_id
7529   , p_accounting_coa_id            => l_adr_accounting_coa_id
7530   , p_adr_code                     => 'CC_COMMON_ADR'
7531   , p_adr_type_code                => 'S'
7532   , p_component_type               => l_component_type
7533   , p_component_code               => l_component_code
7534   , p_component_type_code          => l_component_type_code
7535   , p_component_appl_id            => l_component_appl_id
7536   , p_amb_context_code             => l_amb_context_code
7537   , p_side                         => 'NA'
7538   );
7539 
7540 
7541    --
7542    --
7543    END IF;
7544    --
7545    -- Bug 4922099
7546    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
7547           (NVL(l_enc_upg_option, 'N') = 'O')
7548         ) AND
7549         (l_bflow_method_code = 'PRIOR_ENTRY')
7550       )
7551    THEN
7552       IF
7553       --
7554       1 = 2
7555       --
7556       THEN
7557       xla_accounting_err_pkg.build_message
7558                                     (p_appli_s_name            => 'XLA'
7559                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
7560                                     ,p_token_1                 => 'LINE_NUMBER'
7561                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
7562                                     ,p_token_2                 => 'LINE_TYPE_NAME'
7563                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
7564                                                                              l_component_type
7565                                                                             ,l_component_code
7566                                                                             ,l_component_type_code
7567                                                                             ,l_component_appl_id
7568                                                                             ,l_amb_context_code
7569                                                                             ,l_entity_code
7570                                                                             ,l_event_class_code
7571                                                                            )
7572                                     ,p_token_3                 => 'OWNER'
7573                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
7574                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
7575                                                                           ,p_lookup_code    => l_component_type_code
7576                                                                          )
7577                                     ,p_token_4                 => 'PRODUCT_NAME'
7578                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
7579                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
7580                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
7581                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
7582                                     ,p_ae_header_id            =>  NULL
7583                                        );
7584 
7585         IF (C_LEVEL_ERROR>= g_log_level) THEN
7586                  trace
7587                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
7588                       ,p_level    => C_LEVEL_ERROR
7589                       ,p_module   => l_log_module);
7590         END IF;
7591       END IF;
7592    END IF;
7596    -- 4219869 Business Flow
7593    --
7594    --
7595    ------------------------------------------------------------------------------------------------
7597    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
7598    -- Prior Entry.  Currently, the following code is always generated.
7599    ------------------------------------------------------------------------------------------------
7600    XLA_AE_LINES_PKG.ValidateCurrentLine;
7601 
7602    ------------------------------------------------------------------------------------
7603    -- 4219869 Business Flow
7604    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
7605    ------------------------------------------------------------------------------------
7606    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
7607 
7608    ----------------------------------------------------------------------------------
7609    -- 4219869 Business Flow
7610    -- Update journal entry status -- Need to generate this within IF <condition>
7611    ----------------------------------------------------------------------------------
7612    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
7613          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
7614          ,p_balance_type_code => l_balance_type_code
7615          );
7616 
7617    -------------------------------------------------------------------------------------------
7618    -- 4262811 - Generate the Accrual Reversal lines
7619    -------------------------------------------------------------------------------------------
7620    BEGIN
7621       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
7622                               (g_array_event(p_event_id).array_value_num('header_index'));
7623       IF l_acc_rev_flag IS NULL THEN
7624          l_acc_rev_flag := 'N';
7625       END IF;
7626    EXCEPTION
7627       WHEN OTHERS THEN
7628          l_acc_rev_flag := 'N';
7629    END;
7630    --
7631    IF (l_acc_rev_flag = 'Y') THEN
7632 
7633        -- 4645092  ------------------------------------------------------------------------------
7634        -- To allow MPA report to determine if it should generate report process
7635        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
7636        ------------------------------------------------------------------------------------------
7637 
7638        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
7639        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
7640 
7641        --
7642        -- Update the line information that should be overwritten
7643        --
7644        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
7645                                          p_header_num   => 1);
7646        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
7647 
7648        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
7649 
7650        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
7651           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
7652        END IF;
7653 
7654       --
7655       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
7656       --
7657       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
7658           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
7659       ELSE
7660           ---------------------------------------------------------------------------------------------------
7661           -- 4262811a Switch Sign
7662           ---------------------------------------------------------------------------------------------------
7663           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
7664           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
7665                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
7666           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
7667                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
7668           -- 5132302
7669           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
7670                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
7671 
7672       END IF;
7673 
7674       -- 4955764
7675       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
7676       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
7677 
7678 
7679       XLA_AE_LINES_PKG.ValidateCurrentLine;
7680       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
7681 
7682       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
7683                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
7684                ,p_balance_type_code => l_balance_type_code);
7685 
7686    END IF;
7687 
7688    -----------------------------------------------------------------------------------------
7689    -- 4262811 Multiperiod Accounting
7690    -----------------------------------------------------------------------------------------
7691      -- No MPA option is assigned.
7692 
7693 
7694 END IF;
7695 END IF;
7696 --
7700    trace
7697 
7698 --
7699 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
7701       (p_msg      => 'END of AcctLineType_17'
7702       ,p_level    => C_LEVEL_PROCEDURE
7703       ,p_module   => l_log_module);
7704 END IF;
7705 --
7706 EXCEPTION
7707   WHEN xla_exceptions_pkg.application_exception THEN
7708       RAISE;
7709   WHEN OTHERS THEN
7710        xla_exceptions_pkg.raise_message
7711            (p_location => 'XLA_08407_AAD_S_000013_BC_PKG.AcctLineType_17');
7712 END AcctLineType_17;
7713 --
7714 
7715 ---------------------------------------
7716 --
7717 -- PRIVATE PROCEDURE
7718 --         insert_sources_18
7719 --
7720 ----------------------------------------
7721 --
7722 PROCEDURE insert_sources_18(
7723                                 p_target_ledger_id       IN NUMBER
7724                               , p_language               IN VARCHAR2
7725                               , p_sla_ledger_id          IN NUMBER
7726                               , p_pad_start_date         IN DATE
7727                               , p_pad_end_date           IN DATE
7728                          )
7729 IS
7730 
7731 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'CC_CONTRACT_CMT_ALL';
7732 C_EVENT_CLASS_CODE   CONSTANT  VARCHAR2(30) := 'CC_CONTRACT_CMT';
7733 p_apps_owner                   VARCHAR2(30);
7734 l_log_module                   VARCHAR2(240);
7735 BEGIN
7736 IF g_log_enabled THEN
7737       l_log_module := C_DEFAULT_MODULE||'.insert_sources_18';
7738 END IF;
7739 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
7740 
7741       trace
7742          (p_msg      => 'BEGIN of insert_sources_18'
7743          ,p_level    => C_LEVEL_PROCEDURE
7744          ,p_module   => l_log_module);
7745 
7746 END IF;
7747 
7748 -- select APPS owner
7749 SELECT oracle_username
7750   INTO p_apps_owner
7751   FROM fnd_oracle_userid
7752  WHERE read_only_flag = 'U'
7753 ;
7754 
7755 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
7756       trace
7757          (p_msg      => 'p_target_ledger_id = '||p_target_ledger_id||
7758                         ' - p_language = '||p_language||
7759                         ' - p_sla_ledger_id  = '||p_sla_ledger_id ||
7760                         ' - p_pad_start_date = '||TO_CHAR(p_pad_start_date)||
7761                         ' - p_pad_end_date = '||TO_CHAR(p_pad_end_date)||
7762                         ' - p_apps_owner = '||TO_CHAR(p_apps_owner)
7763          ,p_level    => C_LEVEL_STATEMENT
7764          ,p_module   => l_log_module);
7765 END IF;
7766 
7767 
7768 --
7769 INSERT INTO xla_diag_sources --hdr2
7770 (
7771         event_id
7772       , ledger_id
7773       , sla_ledger_id
7774       , description_language
7775       , object_name
7776       , object_type_code
7777       , line_number
7778       , source_application_id
7779       , source_type_code
7780       , source_code
7781       , source_value
7782       , source_meaning
7783       , created_by
7784       , creation_date
7785       , last_update_date
7786       , last_updated_by
7787       , last_update_login
7788       , program_update_date
7789       , program_application_id
7790       , program_id
7791       , request_id
7792 )
7793 SELECT
7794         event_id
7795       , p_target_ledger_id
7796       , p_sla_ledger_id
7797       , p_language
7798       , object_name
7799       , object_type_code
7800       , line_number
7801       , source_application_id
7802       , source_type_code
7803       , source_code
7804       , SUBSTR(source_value ,1,1996)
7805       , SUBSTR(source_meaning ,1,200)
7806       , xla_environment_pkg.g_Usr_Id
7807       , TRUNC(SYSDATE)
7808       , TRUNC(SYSDATE)
7809       , xla_environment_pkg.g_Usr_Id
7810       , xla_environment_pkg.g_Login_Id
7811       , TRUNC(SYSDATE)
7812       , xla_environment_pkg.g_Prog_Appl_Id
7813       , xla_environment_pkg.g_Prog_Id
7814       , xla_environment_pkg.g_Req_Id
7815   FROM (
7816        SELECT xet.event_id                  event_id
7817             , 0                          line_number
7818             , CASE r
7819                WHEN 1 THEN 'IGC_CC_EVENT_JE_HEADER_V' 
7820                 WHEN 2 THEN 'IGC_CC_EVENT_JE_HEADER_V' 
7821                 WHEN 3 THEN 'IGC_CC_EVENT_JE_HEADER_V' 
7822                 WHEN 4 THEN 'IGC_CC_EVENT_JE_HEADER_V' 
7823                 WHEN 5 THEN 'IGC_CC_EVENT_JE_HEADER_V' 
7824                 
7825                ELSE null
7826               END                           object_name
7827             , CASE r
7828                 WHEN 1 THEN 'HEADER' 
7829                 WHEN 2 THEN 'HEADER' 
7830                 WHEN 3 THEN 'HEADER' 
7831                 WHEN 4 THEN 'HEADER' 
7832                 WHEN 5 THEN 'HEADER' 
7833                 
7834                 ELSE null
7835               END                           object_type_code
7836             , CASE r
7837                 WHEN 1 THEN '8407' 
7838                 WHEN 2 THEN '8407' 
7839                 WHEN 3 THEN '8407' 
7840                 WHEN 4 THEN '8407' 
7841                 WHEN 5 THEN '8407' 
7842                 
7843                 ELSE null
7844               END                           source_application_id
7845             , 'S'             source_type_code
7846             , CASE r
7847                 WHEN 1 THEN 'HEADER_DESC' 
7851                 WHEN 5 THEN 'ACCOUNTING_DATE' 
7848                 WHEN 2 THEN 'REFERENCE_4' 
7849                 WHEN 3 THEN 'REFERENCE_3' 
7850                 WHEN 4 THEN 'DOCUMENT_TYPE' 
7852                 
7853                 ELSE null
7854               END                           source_code
7855             , CASE r
7856                 WHEN 1 THEN TO_CHAR(h1.HEADER_DESC)
7857                 WHEN 2 THEN TO_CHAR(h1.REFERENCE_4)
7858                 WHEN 3 THEN TO_CHAR(h1.REFERENCE_3)
7859                 WHEN 4 THEN TO_CHAR(h1.DOCUMENT_TYPE)
7860                 WHEN 5 THEN TO_CHAR(h1.ACCOUNTING_DATE)
7861                 
7862                 ELSE null
7863               END                           source_value
7864             , null              source_meaning
7865          FROM xla_events_gt     xet  
7866       , IGC_CC_EVENT_JE_HEADER_V  h1
7867              ,(select rownum r from all_objects where rownum <= 5 and owner = p_apps_owner)
7868          WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
7869            AND xet.event_class_code = C_EVENT_CLASS_CODE
7870               AND h1.event_id = xet.event_id
7871 
7872 )
7873 ;
7874 --
7875 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
7876 
7877       trace
7878          (p_msg      => 'number of header sources inserted = '||SQL%ROWCOUNT
7879          ,p_level    => C_LEVEL_STATEMENT
7880          ,p_module   => l_log_module);
7881 
7882 END IF;
7883 --
7884 
7885 
7886 
7887 --
7888 INSERT INTO xla_diag_sources  --line2
7889 (
7890         event_id
7891       , ledger_id
7892       , sla_ledger_id
7893       , description_language
7894       , object_name
7895       , object_type_code
7896       , line_number
7897       , source_application_id
7898       , source_type_code
7899       , source_code
7900       , source_value
7901       , source_meaning
7902       , created_by
7903       , creation_date
7904       , last_update_date
7905       , last_updated_by
7906       , last_update_login
7907       , program_update_date
7908       , program_application_id
7909       , program_id
7910       , request_id
7911 )
7912 SELECT  event_id
7913       , p_target_ledger_id
7914       , p_sla_ledger_id
7915       , p_language
7916       , object_name
7917       , object_type_code
7918       , line_number
7919       , source_application_id
7920       , source_type_code
7921       , source_code
7922       , SUBSTR(source_value,1,1996)
7923       , SUBSTR(source_meaning ,1,200)
7924       , xla_environment_pkg.g_Usr_Id
7925       , TRUNC(SYSDATE)
7926       , TRUNC(SYSDATE)
7927       , xla_environment_pkg.g_Usr_Id
7928       , xla_environment_pkg.g_Login_Id
7929       , TRUNC(SYSDATE)
7930       , xla_environment_pkg.g_Prog_Appl_Id
7931       , xla_environment_pkg.g_Prog_Id
7932       , xla_environment_pkg.g_Req_Id
7933   FROM (
7934        SELECT xet.event_id                  event_id
7935             , l2.line_number                 line_number
7936             , CASE r
7937                WHEN 1 THEN 'IGC_CC_EVENT_JE_LINES_V' 
7938                 WHEN 2 THEN 'IGC_CC_EVENT_JE_LINES_V' 
7939                 WHEN 3 THEN 'IGC_CC_EVENT_JE_LINES_V' 
7940                 WHEN 4 THEN 'IGC_CC_EVENT_JE_LINES_V' 
7941                 WHEN 5 THEN 'IGC_CC_EVENT_JE_LINES_V' 
7942                 WHEN 6 THEN 'IGC_CC_EVENT_JE_LINES_V' 
7943                 WHEN 7 THEN 'IGC_CC_EVENT_JE_LINES_V' 
7944                 WHEN 8 THEN 'IGC_CC_EVENT_JE_LINES_V' 
7945                 WHEN 9 THEN 'IGC_CC_EVENT_JE_LINES_V' 
7946                 WHEN 10 THEN 'IGC_CC_EVENT_JE_LINES_V' 
7947                 WHEN 11 THEN 'IGC_CC_EVENT_JE_LINES_V' 
7948                 WHEN 12 THEN 'IGC_CC_EVENT_JE_LINES_V' 
7949                 WHEN 13 THEN 'IGC_CC_EVENT_JE_LINES_V' 
7950                 
7951                ELSE null
7952               END                           object_name
7953             , CASE r
7954                 WHEN 1 THEN 'LINE' 
7955                 WHEN 2 THEN 'LINE' 
7956                 WHEN 3 THEN 'LINE' 
7957                 WHEN 4 THEN 'LINE' 
7958                 WHEN 5 THEN 'LINE' 
7959                 WHEN 6 THEN 'LINE' 
7960                 WHEN 7 THEN 'LINE' 
7961                 WHEN 8 THEN 'LINE' 
7962                 WHEN 9 THEN 'LINE' 
7963                 WHEN 10 THEN 'LINE' 
7964                 WHEN 11 THEN 'LINE' 
7965                 WHEN 12 THEN 'LINE' 
7966                 WHEN 13 THEN 'LINE' 
7967                 
7968                 ELSE null
7969               END                           object_type_code
7970             , CASE r
7971                 WHEN 1 THEN '8407' 
7972                 WHEN 2 THEN '8407' 
7973                 WHEN 3 THEN '8407' 
7974                 WHEN 4 THEN '8407' 
7975                 WHEN 5 THEN '8407' 
7976                 WHEN 6 THEN '8407' 
7977                 WHEN 7 THEN '8407' 
7978                 WHEN 8 THEN '8407' 
7979                 WHEN 9 THEN '8407' 
7980                 WHEN 10 THEN '8407' 
7981                 WHEN 11 THEN '8407' 
7982                 WHEN 12 THEN '8407' 
7983                 WHEN 13 THEN '8407' 
7984                 
7985                 ELSE null
7986               END                           source_application_id
7987             , 'S'             source_type_code
7988             , CASE r
7992                 WHEN 4 THEN 'PROJECT_LINE' 
7989                 WHEN 1 THEN 'TRANSACTION_DESCRIPTION' 
7990                 WHEN 2 THEN 'CODE_COMBINATION_ID' 
7991                 WHEN 3 THEN 'CC_FUNC_CR_AMT' 
7993                 WHEN 5 THEN 'CC_ACCT_LINE_ID' 
7994                 WHEN 6 THEN 'CC_FUNC_AMT' 
7995                 WHEN 7 THEN 'CURRENCY_CODE' 
7996                 WHEN 8 THEN 'CC_FUNC_DR_AMT' 
7997                 WHEN 9 THEN 'APPLIED_TO_APPL_ID' 
7998                 WHEN 10 THEN 'APPLIED_TO_DIST_LINK_TYPE' 
7999                 WHEN 11 THEN 'APPLIED_TO_ENTITY_CODE' 
8000                 WHEN 12 THEN 'APPLIED_TO_DIST_ID_1' 
8001                 WHEN 13 THEN 'APPLIED_TO_HEADER_ID_1' 
8002                 
8003                 ELSE null
8004               END                           source_code
8005             , CASE r
8006                 WHEN 1 THEN TO_CHAR(l2.TRANSACTION_DESCRIPTION)
8007                 WHEN 2 THEN TO_CHAR(l2.CODE_COMBINATION_ID)
8008                 WHEN 3 THEN TO_CHAR(l2.CC_FUNC_CR_AMT)
8009                 WHEN 4 THEN TO_CHAR(l2.PROJECT_LINE)
8010                 WHEN 5 THEN TO_CHAR(l2.CC_ACCT_LINE_ID)
8011                 WHEN 6 THEN TO_CHAR(l2.CC_FUNC_AMT)
8012                 WHEN 7 THEN TO_CHAR(l2.CURRENCY_CODE)
8013                 WHEN 8 THEN TO_CHAR(l2.CC_FUNC_DR_AMT)
8014                 WHEN 9 THEN TO_CHAR(l2.APPLIED_TO_APPL_ID)
8015                 WHEN 10 THEN TO_CHAR(l2.APPLIED_TO_DIST_LINK_TYPE)
8016                 WHEN 11 THEN TO_CHAR(l2.APPLIED_TO_ENTITY_CODE)
8017                 WHEN 12 THEN TO_CHAR(l2.APPLIED_TO_DIST_ID_1)
8018                 WHEN 13 THEN TO_CHAR(l2.APPLIED_TO_HEADER_ID_1)
8019                 
8020                 ELSE null
8021               END                           source_value
8022             , null              source_meaning
8023          FROM  xla_events_gt     xet  
8024         , IGC_CC_EVENT_JE_LINES_V  l2
8025             , (select rownum r from all_objects where rownum <= 13 and owner = p_apps_owner)
8026         WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
8027           AND xet.event_class_code = C_EVENT_CLASS_CODE
8028             AND l2.event_id          = xet.event_id
8029 
8030 )
8031 ;
8032 --
8033 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
8034 
8035       trace
8036          (p_msg      => 'number of line sources inserted = '||SQL%ROWCOUNT
8037          ,p_level    => C_LEVEL_STATEMENT
8038          ,p_module   => l_log_module);
8039 
8040 END IF;
8041 
8042 
8043 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
8044       trace
8045          (p_msg      => 'END of insert_sources_18'
8046          ,p_level    => C_LEVEL_PROCEDURE
8047          ,p_module   => l_log_module);
8048 END IF;
8049 EXCEPTION
8050   WHEN xla_exceptions_pkg.application_exception THEN
8051       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
8052             trace
8053                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
8054                ,p_level    => C_LEVEL_EXCEPTION
8055                ,p_module   => l_log_module);
8056       END IF;
8057       RAISE;
8058   WHEN OTHERS THEN
8059       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
8060             trace
8061                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
8062                ,p_level    => C_LEVEL_EXCEPTION
8063                ,p_module   => l_log_module);
8064        END IF;
8065        xla_exceptions_pkg.raise_message
8066            (p_location => 'XLA_08407_AAD_S_000013_BC_PKG.insert_sources_18');
8067 END insert_sources_18;
8068 --
8069 
8070 ---------------------------------------
8071 --
8072 -- PRIVATE FUNCTION
8073 --         EventClass_18
8074 --
8075 ----------------------------------------
8076 --
8077 FUNCTION EventClass_18
8078        (p_application_id         IN NUMBER
8079        ,p_base_ledger_id         IN NUMBER
8080        ,p_target_ledger_id       IN NUMBER
8081        ,p_language               IN VARCHAR2
8082        ,p_currency_code          IN VARCHAR2
8083        ,p_sla_ledger_id          IN NUMBER
8084        ,p_pad_start_date         IN DATE
8085        ,p_pad_end_date           IN DATE
8086        ,p_primary_ledger_id      IN NUMBER)
8087 RETURN BOOLEAN IS
8088 --
8089 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'CC_CONTRACT_CMT_ALL';
8090 C_EVENT_CLASS_CODE    CONSTANT  VARCHAR2(30) := 'CC_CONTRACT_CMT';
8091 
8092 l_calculate_acctd_flag   VARCHAR2(1) :='N';
8093 l_calculate_g_l_flag     VARCHAR2(1) :='N';
8094 --
8095 l_array_legal_entity_id                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
8096 l_array_entity_id                      XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
8097 l_array_entity_code                    XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
8098 l_array_transaction_num                XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
8099 l_array_event_id                       XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
8100 l_array_class_code                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
8101 l_array_event_type                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
8102 l_array_event_number                   XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
8103 l_array_event_date                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
8104 l_array_transaction_date               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
8105 l_array_reference_num_1                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
8106 l_array_reference_num_2                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
8110 l_array_reference_char_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
8107 l_array_reference_num_3                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
8108 l_array_reference_num_4                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
8109 l_array_reference_char_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
8111 l_array_reference_char_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
8112 l_array_reference_char_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
8113 l_array_reference_date_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
8114 l_array_reference_date_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
8115 l_array_reference_date_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
8116 l_array_reference_date_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
8117 l_array_event_created_by               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V100L;
8118 l_array_budgetary_control_flag         XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
8119 
8120 l_event_id                             NUMBER;
8121 l_previous_event_id                    NUMBER;
8122 l_first_event_id                       NUMBER;
8123 l_last_event_id                        NUMBER;
8124 
8125 l_rec_acct_attrs                       XLA_AE_HEADER_PKG.t_rec_acct_attrs;
8126 l_rec_rev_acct_attrs                   XLA_AE_LINES_PKG.t_rec_acct_attrs;
8127 --
8128 --
8129 l_result                    BOOLEAN := TRUE;
8130 l_rows                      NUMBER  := 1000;
8131 l_event_type_name           VARCHAR2(80) := 'All';
8132 l_event_class_name          VARCHAR2(80) := 'CC Contract Commitment';
8133 l_description               VARCHAR2(4000);
8134 l_transaction_reversal      NUMBER;
8135 l_ae_header_id              NUMBER;
8136 l_array_extract_line_num    xla_ae_journal_entry_pkg.t_array_Num;
8137 l_log_module                VARCHAR2(240);
8138 --
8139 l_acct_reversal_source      VARCHAR2(30);
8140 l_trx_reversal_source       VARCHAR2(30);
8141 
8142 l_continue_with_lines       BOOLEAN := TRUE;
8143 --
8144 l_acc_rev_gl_date_source    DATE;                      -- 4262811
8145 --
8146 type t_array_event_id is table of number index by binary_integer;
8147 
8148 l_rec_array_event                    t_rec_array_event;
8149 l_null_rec_array_event               t_rec_array_event;
8150 l_array_ae_header_id                 xla_number_array_type;
8151 l_actual_flag                        VARCHAR2(1) := NULL;
8152 l_actual_gain_loss_ref               VARCHAR2(30) := '#####';
8153 l_balance_type_code                  VARCHAR2(1) :=NULL;
8154 l_gain_or_loss_ref                   VARCHAR2(30) :=NULL;
8155 
8156 --
8157 TYPE t_array_lookup_meaning IS TABLE OF fnd_lookup_values.meaning%TYPE INDEX BY BINARY_INTEGER;
8158 --
8159 
8160 TYPE t_array_source_2 IS TABLE OF IGC_CC_EVENT_JE_HEADER_V.HEADER_DESC%TYPE INDEX BY BINARY_INTEGER;
8161 TYPE t_array_source_3 IS TABLE OF IGC_CC_EVENT_JE_HEADER_V.REFERENCE_4%TYPE INDEX BY BINARY_INTEGER;
8162 TYPE t_array_source_4 IS TABLE OF IGC_CC_EVENT_JE_HEADER_V.REFERENCE_3%TYPE INDEX BY BINARY_INTEGER;
8163 TYPE t_array_source_9 IS TABLE OF IGC_CC_EVENT_JE_HEADER_V.DOCUMENT_TYPE%TYPE INDEX BY BINARY_INTEGER;
8164 TYPE t_array_source_18 IS TABLE OF IGC_CC_EVENT_JE_HEADER_V.ACCOUNTING_DATE%TYPE INDEX BY BINARY_INTEGER;
8165 
8166 TYPE t_array_source_1 IS TABLE OF IGC_CC_EVENT_JE_LINES_V.TRANSACTION_DESCRIPTION%TYPE INDEX BY BINARY_INTEGER;
8167 TYPE t_array_source_5 IS TABLE OF IGC_CC_EVENT_JE_LINES_V.CODE_COMBINATION_ID%TYPE INDEX BY BINARY_INTEGER;
8168 TYPE t_array_source_6 IS TABLE OF IGC_CC_EVENT_JE_LINES_V.CC_FUNC_CR_AMT%TYPE INDEX BY BINARY_INTEGER;
8169 TYPE t_array_source_7 IS TABLE OF IGC_CC_EVENT_JE_LINES_V.PROJECT_LINE%TYPE INDEX BY BINARY_INTEGER;
8170 TYPE t_array_source_8 IS TABLE OF IGC_CC_EVENT_JE_LINES_V.CC_ACCT_LINE_ID%TYPE INDEX BY BINARY_INTEGER;
8171 TYPE t_array_source_10 IS TABLE OF IGC_CC_EVENT_JE_LINES_V.CC_FUNC_AMT%TYPE INDEX BY BINARY_INTEGER;
8172 TYPE t_array_source_11 IS TABLE OF IGC_CC_EVENT_JE_LINES_V.CURRENCY_CODE%TYPE INDEX BY BINARY_INTEGER;
8173 TYPE t_array_source_12 IS TABLE OF IGC_CC_EVENT_JE_LINES_V.CC_FUNC_DR_AMT%TYPE INDEX BY BINARY_INTEGER;
8174 TYPE t_array_source_13 IS TABLE OF IGC_CC_EVENT_JE_LINES_V.APPLIED_TO_APPL_ID%TYPE INDEX BY BINARY_INTEGER;
8175 TYPE t_array_source_14 IS TABLE OF IGC_CC_EVENT_JE_LINES_V.APPLIED_TO_DIST_LINK_TYPE%TYPE INDEX BY BINARY_INTEGER;
8176 TYPE t_array_source_15 IS TABLE OF IGC_CC_EVENT_JE_LINES_V.APPLIED_TO_ENTITY_CODE%TYPE INDEX BY BINARY_INTEGER;
8177 TYPE t_array_source_16 IS TABLE OF IGC_CC_EVENT_JE_LINES_V.APPLIED_TO_DIST_ID_1%TYPE INDEX BY BINARY_INTEGER;
8178 TYPE t_array_source_17 IS TABLE OF IGC_CC_EVENT_JE_LINES_V.APPLIED_TO_HEADER_ID_1%TYPE INDEX BY BINARY_INTEGER;
8179 
8180 l_array_source_2              t_array_source_2;
8181 l_array_source_3              t_array_source_3;
8182 l_array_source_4              t_array_source_4;
8183 l_array_source_9              t_array_source_9;
8184 l_array_source_18              t_array_source_18;
8185 
8186 l_array_source_1      t_array_source_1;
8187 l_array_source_5      t_array_source_5;
8188 l_array_source_6      t_array_source_6;
8189 l_array_source_7      t_array_source_7;
8190 l_array_source_8      t_array_source_8;
8191 l_array_source_10      t_array_source_10;
8192 l_array_source_11      t_array_source_11;
8193 l_array_source_12      t_array_source_12;
8194 l_array_source_13      t_array_source_13;
8195 l_array_source_14      t_array_source_14;
8196 l_array_source_15      t_array_source_15;
8197 l_array_source_16      t_array_source_16;
8198 l_array_source_17      t_array_source_17;
8199 
8200 --
8201 CURSOR header_cur
8202 IS
8203 SELECT /*+ leading(xet) cardinality(xet,1) */
8207    ,xet.entity_code
8204 -- Event Class Code: CC_CONTRACT_CMT
8205     xet.entity_id
8206    ,xet.legal_entity_id
8208    ,xet.transaction_number
8209    ,xet.event_id
8210    ,xet.event_class_code
8211    ,xet.event_type_code
8212    ,xet.event_number
8213    ,xet.event_date
8214    ,xet.transaction_date
8215    ,xet.reference_num_1
8216    ,xet.reference_num_2
8217    ,xet.reference_num_3
8218    ,xet.reference_num_4
8219    ,xet.reference_char_1
8220    ,xet.reference_char_2
8221    ,xet.reference_char_3
8222    ,xet.reference_char_4
8223    ,xet.reference_date_1
8224    ,xet.reference_date_2
8225    ,xet.reference_date_3
8226    ,xet.reference_date_4
8227    ,xet.event_created_by
8228    ,xet.budgetary_control_flag 
8229   , h1.HEADER_DESC    source_2
8230   , h1.REFERENCE_4    source_3
8231   , h1.REFERENCE_3    source_4
8232   , h1.DOCUMENT_TYPE    source_9
8233   , h1.ACCOUNTING_DATE    source_18
8234   FROM xla_events_gt     xet 
8235   , IGC_CC_EVENT_JE_HEADER_V  h1
8236  WHERE xet.event_date between p_pad_start_date and p_pad_end_date
8237    and xet.event_class_code = C_EVENT_CLASS_CODE
8238    and xet.event_status_code <> 'N'  AND h1.event_id = xet.event_id
8239 
8240  ORDER BY event_id
8241 ;
8242 
8243 
8244 --
8245 CURSOR line_cur (x_first_event_id    in number, x_last_event_id    in number)
8246 IS
8247 SELECT  /*+ leading(xet) cardinality(xet,1) */
8248 -- Event Class Code: CC_CONTRACT_CMT
8249     xet.entity_id
8250    ,xet.legal_entity_id
8251    ,xet.entity_code
8252    ,xet.transaction_number
8253    ,xet.event_id
8254    ,xet.event_class_code
8255    ,xet.event_type_code
8256    ,xet.event_number
8257    ,xet.event_date
8258    ,xet.transaction_date
8259    ,xet.reference_num_1
8260    ,xet.reference_num_2
8261    ,xet.reference_num_3
8262    ,xet.reference_num_4
8263    ,xet.reference_char_1
8264    ,xet.reference_char_2
8265    ,xet.reference_char_3
8266    ,xet.reference_char_4
8267    ,xet.reference_date_1
8268    ,xet.reference_date_2
8269    ,xet.reference_date_3
8270    ,xet.reference_date_4
8271    ,xet.event_created_by
8272    ,xet.budgetary_control_flag
8273  , l2.LINE_NUMBER  
8274   , l2.TRANSACTION_DESCRIPTION    source_1
8275   , l2.CODE_COMBINATION_ID    source_5
8276   , l2.CC_FUNC_CR_AMT    source_6
8277   , l2.PROJECT_LINE    source_7
8278   , l2.CC_ACCT_LINE_ID    source_8
8279   , l2.CC_FUNC_AMT    source_10
8280   , l2.CURRENCY_CODE    source_11
8281   , l2.CC_FUNC_DR_AMT    source_12
8282   , l2.APPLIED_TO_APPL_ID    source_13
8283   , l2.APPLIED_TO_DIST_LINK_TYPE    source_14
8284   , l2.APPLIED_TO_ENTITY_CODE    source_15
8285   , l2.APPLIED_TO_DIST_ID_1    source_16
8286   , l2.APPLIED_TO_HEADER_ID_1    source_17
8287   FROM xla_events_gt     xet 
8288   , IGC_CC_EVENT_JE_LINES_V  l2
8289  WHERE xet.event_id between x_first_event_id and x_last_event_id
8290    and xet.event_date between p_pad_start_date and p_pad_end_date
8291    and xet.event_class_code = C_EVENT_CLASS_CODE
8292    and xet.event_status_code <> 'N'   AND l2.event_id      = xet.event_id
8293 ;
8294 
8295 --
8296 BEGIN
8297 IF g_log_enabled THEN
8298    l_log_module := C_DEFAULT_MODULE||'.EventClass_18';
8299 END IF;
8300 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
8301    trace
8302       (p_msg      => 'BEGIN of EventClass_18'
8303       ,p_level    => C_LEVEL_PROCEDURE
8304       ,p_module   => l_log_module);
8305 END IF;
8306 
8307 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
8308    trace
8309       (p_msg      => 'p_application_id = '||p_application_id||
8310                      ' - p_base_ledger_id = '||p_base_ledger_id||
8311                      ' - p_target_ledger_id  = '||p_target_ledger_id||
8312                      ' - p_language = '||p_language||
8313                      ' - p_currency_code = '||p_currency_code||
8314                      ' - p_sla_ledger_id = '||p_sla_ledger_id
8315       ,p_level    => C_LEVEL_STATEMENT
8316       ,p_module   => l_log_module);
8317 END IF;
8318 --
8319 -- initialze arrays
8320 --
8321 g_array_event.DELETE;
8322 l_rec_array_event := l_null_rec_array_event;
8323 --
8324 --------------------------------------
8325 -- 4262811 Initialze MPA Line Number
8326 --------------------------------------
8327 XLA_AE_HEADER_PKG.g_mpa_line_num := 0;
8328 
8329 --
8330 
8331 --
8332 OPEN header_cur;
8333 --
8334 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
8335    trace
8336    (p_msg      => 'SQL - FETCH header_cur'
8337    ,p_level    => C_LEVEL_STATEMENT
8338    ,p_module   => l_log_module);
8339 END IF;
8340 --
8341 LOOP
8342 FETCH header_cur BULK COLLECT INTO
8343         l_array_entity_id
8344       , l_array_legal_entity_id
8345       , l_array_entity_code
8346       , l_array_transaction_num
8347       , l_array_event_id
8348       , l_array_class_code
8349       , l_array_event_type
8350       , l_array_event_number
8351       , l_array_event_date
8352       , l_array_transaction_date
8353       , l_array_reference_num_1
8354       , l_array_reference_num_2
8355       , l_array_reference_num_3
8356       , l_array_reference_num_4
8357       , l_array_reference_char_1
8358       , l_array_reference_char_2
8359       , l_array_reference_char_3
8360       , l_array_reference_char_4
8361       , l_array_reference_date_1
8365       , l_array_event_created_by
8362       , l_array_reference_date_2
8363       , l_array_reference_date_3
8364       , l_array_reference_date_4
8366       , l_array_budgetary_control_flag 
8367       , l_array_source_2
8368       , l_array_source_3
8369       , l_array_source_4
8370       , l_array_source_9
8371       , l_array_source_18
8372       LIMIT l_rows;
8373 --
8374 IF (C_LEVEL_EVENT >= g_log_level) THEN
8375    trace
8376    (p_msg      => '# rows extracted from header extract objects = '||TO_CHAR(header_cur%ROWCOUNT)
8377    ,p_level    => C_LEVEL_EVENT
8378    ,p_module   => l_log_module);
8379 END IF;
8380 --
8381 EXIT WHEN l_array_entity_id.COUNT = 0;
8382 
8383 -- initialize arrays
8384 XLA_AE_HEADER_PKG.g_rec_header_new        := NULL;
8385 XLA_AE_LINES_PKG.g_rec_lines              := NULL;
8386 
8387 --
8388 -- Bug 4458708
8389 --
8390 XLA_AE_LINES_PKG.g_LineNumber := 0;
8391 
8392 
8393 -- 4262811 - when creating Accrual Reversal or MPA, use g_last_hdr_idx to increment for next header id
8394 g_last_hdr_idx := l_array_event_id.LAST;
8395 --
8396 -- loop for the headers. Each iteration is for each header extract row
8397 -- fetched in header cursor
8398 --
8399 FOR hdr_idx IN l_array_event_id.FIRST .. l_array_event_id.LAST LOOP
8400 
8401 --
8402 -- set event info as cache for other routines to refer event attributes
8403 --
8404 XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
8405    (p_application_id           => p_application_id
8406    ,p_primary_ledger_id        => p_primary_ledger_id
8407    ,p_base_ledger_id           => p_base_ledger_id
8408    ,p_target_ledger_id         => p_target_ledger_id
8409    ,p_entity_id                => l_array_entity_id(hdr_idx)
8410    ,p_legal_entity_id          => l_array_legal_entity_id(hdr_idx)
8411    ,p_entity_code              => l_array_entity_code(hdr_idx)
8412    ,p_transaction_num          => l_array_transaction_num(hdr_idx)
8413    ,p_event_id                 => l_array_event_id(hdr_idx)
8414    ,p_event_class_code         => l_array_class_code(hdr_idx)
8415    ,p_event_type_code          => l_array_event_type(hdr_idx)
8416    ,p_event_number             => l_array_event_number(hdr_idx)
8417    ,p_event_date               => l_array_event_date(hdr_idx)
8418    ,p_transaction_date         => l_array_transaction_date(hdr_idx)
8419    ,p_reference_num_1          => l_array_reference_num_1(hdr_idx)
8420    ,p_reference_num_2          => l_array_reference_num_2(hdr_idx)
8421    ,p_reference_num_3          => l_array_reference_num_3(hdr_idx)
8422    ,p_reference_num_4          => l_array_reference_num_4(hdr_idx)
8423    ,p_reference_char_1         => l_array_reference_char_1(hdr_idx)
8424    ,p_reference_char_2         => l_array_reference_char_2(hdr_idx)
8425    ,p_reference_char_3         => l_array_reference_char_3(hdr_idx)
8426    ,p_reference_char_4         => l_array_reference_char_4(hdr_idx)
8427    ,p_reference_date_1         => l_array_reference_date_1(hdr_idx)
8428    ,p_reference_date_2         => l_array_reference_date_2(hdr_idx)
8429    ,p_reference_date_3         => l_array_reference_date_3(hdr_idx)
8430    ,p_reference_date_4         => l_array_reference_date_4(hdr_idx)
8431    ,p_event_created_by         => l_array_event_created_by(hdr_idx)
8432    ,p_budgetary_control_flag   => l_array_budgetary_control_flag(hdr_idx));
8433 
8434 --
8435 -- set the status of entry to C_VALID (0)
8436 --
8437 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status    := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
8438 
8439 --
8440 -- initialize a row for ae header
8441 --
8442 XLA_AE_HEADER_PKG.InitHeader(hdr_idx);
8443 
8444 l_event_id := l_array_event_id(hdr_idx);
8445 
8446 --
8447 -- storing the hdr_idx for event. May be used by line cursor.
8448 --
8449 g_array_event(l_event_id).array_value_num('header_index') := hdr_idx;
8450 
8451 --
8452 -- store sources from header extract. This can be improved to
8453 -- store only those sources from header extract that may be used in lines
8454 --
8455 
8456 g_array_event(l_event_id).array_value_char('source_2') := l_array_source_2(hdr_idx);
8457 g_array_event(l_event_id).array_value_char('source_3') := l_array_source_3(hdr_idx);
8458 g_array_event(l_event_id).array_value_char('source_4') := l_array_source_4(hdr_idx);
8459 g_array_event(l_event_id).array_value_char('source_9') := l_array_source_9(hdr_idx);
8460 g_array_event(l_event_id).array_value_date('source_18') := l_array_source_18(hdr_idx);
8461 
8462 --
8463 -- initilaize the status of ae headers for diffrent balance types
8464 -- the status is initialised to C_NOT_CREATED (2)
8465 --
8466 --g_array_event(l_event_id).array_value_num('actual_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
8467 --g_array_event(l_event_id).array_value_num('budget_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
8468 --g_array_event(l_event_id).array_value_num('encumbrance_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
8469 
8470 --
8471 -- call api to validate and store accounting attributes for header
8472 --
8473 
8474 ------------------------------------------------------------
8475 -- Accrual Reversal : to get date for Standard Source (NONE)
8476 ------------------------------------------------------------
8477 l_acc_rev_gl_date_source := NULL;
8478 
8479      l_rec_acct_attrs.array_acct_attr_code(1)   := 'GL_DATE';
8480       l_rec_acct_attrs.array_date_value(1) := g_array_event(l_event_id).array_value_date('source_18');
8481 
8482 
8483 XLA_AE_HEADER_PKG.SetHdrAcctAttrs(l_rec_acct_attrs);
8484 
8488 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_id(hdr_idx)         := l_array_event_id(hdr_idx);
8485 XLA_AE_HEADER_PKG.SetJeCategoryName;
8486 
8487 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_type_code(hdr_idx)  := l_array_event_type(hdr_idx);
8489 XLA_AE_HEADER_PKG.g_rec_header_new.array_entity_id(hdr_idx)        := l_array_entity_id(hdr_idx);
8490 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_number(hdr_idx)     := l_array_event_number(hdr_idx);
8491 XLA_AE_HEADER_PKG.g_rec_header_new.array_target_ledger_id(hdr_idx) := p_target_ledger_id;
8492 
8493 
8494 --
8495 xla_ae_header_pkg.SetHdrDescription(
8496    p_description => Description_2 (
8497    p_application_id => p_application_id 
8498  , p_source_2 => g_array_event(l_event_id).array_value_char('source_2')
8499  , p_source_3 => g_array_event(l_event_id).array_value_char('source_3')
8500  , p_source_4 => g_array_event(l_event_id).array_value_char('source_4')
8501    )
8502 );
8503 --
8504 
8505 -- No header level analytical criteria
8506 
8507 --
8508 --accounting attribute enhancement, bug 3612931
8509 --
8510 l_trx_reversal_source := SUBSTR(NULL, 1,30);
8511 
8512 IF NVL(l_trx_reversal_source, 'N') NOT IN ('N','Y') THEN
8513    xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
8514 
8515    xla_accounting_err_pkg.build_message
8516       (p_appli_s_name            => 'XLA'
8517       ,p_msg_name                => 'XLA_AP_INVALID_HDR_ATTR'
8518       ,p_token_1                 => 'ACCT_ATTR_NAME'
8519       ,p_value_1                 => xla_ae_sources_pkg.GetAccountingSourceName('TRX_ACCT_REVERSAL_OPTION')
8520       ,p_token_2                 => 'PRODUCT_NAME'
8521       ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
8522       ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
8523       ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
8524       ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
8525 
8526 ELSIF NVL(l_trx_reversal_source, 'N') = 'Y' THEN
8527    --
8528    -- following sets the accounting attributes needed to reverse
8529    -- accounting for a distributeion
8530    --
8531    xla_ae_lines_pkg.SetTrxReversalAttrs
8532       (p_event_id              => l_event_id
8533       ,p_gl_date               => XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(hdr_idx)
8534       ,p_trx_reversal_source   => l_trx_reversal_source);
8535 
8536 END IF;
8537 
8538 
8539 ----------------------------------------------------------------
8540 -- 4262811 -  update the header statuses to invalid in need be
8541 ----------------------------------------------------------------
8542 --
8543 XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus (p_hdr_idx => hdr_idx);
8544 
8545 
8546   -----------------------------------------------
8547   -- No accrual reversal for the event class/type
8548   -----------------------------------------------
8549 ----------------------------------------------------------------
8550 
8551 --
8552 -- this ends the header loop iteration for one bulk fetch
8553 --
8554 END LOOP;
8555 
8556 l_first_event_id   := l_array_event_id(l_array_event_id.FIRST);
8557 l_last_event_id    := l_array_event_id(l_array_event_id.LAST);
8558 
8559 --
8560 -- insert dummy rows into lines gt table that were created due to
8561 -- transaction reversals
8562 --
8563 IF XLA_AE_LINES_PKG.g_rec_lines.array_ae_header_id.COUNT > 0 THEN
8564    l_result := XLA_AE_LINES_PKG.InsertLines;
8565 END IF;
8566 
8567 --
8568 -- reset the temp_line_num for each set of events fetched from header
8569 -- cursor rather than doing it for each new event in line cursor
8570 -- Bug 3939231
8571 --
8572 xla_ae_lines_pkg.g_temp_line_num := 0;
8573 
8574 
8575 
8576 --
8577 OPEN line_cur(x_first_event_id  => l_first_event_id, x_last_event_id  => l_last_event_id);
8578 --
8579 --
8580 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
8581 
8582       trace
8583          (p_msg      => 'SQL - FETCH line_cur'
8584          ,p_level    => C_LEVEL_STATEMENT
8585          ,p_module   => l_log_module);
8586 
8587 END IF;
8588 --
8589 --
8590 LOOP
8591   --
8592   FETCH line_cur BULK COLLECT INTO
8593         l_array_entity_id
8594       , l_array_legal_entity_id
8595       , l_array_entity_code
8596       , l_array_transaction_num
8597       , l_array_event_id
8598       , l_array_class_code
8599       , l_array_event_type
8600       , l_array_event_number
8601       , l_array_event_date
8602       , l_array_transaction_date
8603       , l_array_reference_num_1
8604       , l_array_reference_num_2
8605       , l_array_reference_num_3
8606       , l_array_reference_num_4
8607       , l_array_reference_char_1
8608       , l_array_reference_char_2
8609       , l_array_reference_char_3
8610       , l_array_reference_char_4
8611       , l_array_reference_date_1
8612       , l_array_reference_date_2
8613       , l_array_reference_date_3
8614       , l_array_reference_date_4
8615       , l_array_event_created_by
8616       , l_array_budgetary_control_flag
8617       , l_array_extract_line_num 
8618       , l_array_source_1
8619       , l_array_source_5
8620       , l_array_source_6
8621       , l_array_source_7
8622       , l_array_source_8
8626       , l_array_source_13
8623       , l_array_source_10
8624       , l_array_source_11
8625       , l_array_source_12
8627       , l_array_source_14
8628       , l_array_source_15
8629       , l_array_source_16
8630       , l_array_source_17
8631       LIMIT l_rows;
8632 
8633   --
8634   IF (C_LEVEL_EVENT >= g_log_level) THEN
8635             trace
8636                (p_msg      => '# rows extracted from line extract objects = '||TO_CHAR(line_cur%ROWCOUNT)
8637                ,p_level    => C_LEVEL_EVENT
8638                ,p_module   => l_log_module);
8639   END IF;
8640   --
8641   EXIT WHEN l_array_entity_id.count = 0;
8642 
8643   XLA_AE_LINES_PKG.g_rec_lines := null;
8644 
8645 --
8646 -- Bug 4458708
8647 --
8648 XLA_AE_LINES_PKG.g_LineNumber := 0;
8649 --
8650 --
8651 
8652 FOR Idx IN 1..l_array_event_id.count LOOP
8653    --
8654    -- 5648433 (move l_event_id out of IF statement)  set l_event_id to be used inside IF condition
8655    --
8656    l_event_id := l_array_event_id(idx);  -- 5648433
8657 
8658    --
8659    -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
8660    --
8661 
8662    IF NVL(xla_ae_header_pkg.g_rec_header_new.array_trx_acct_reversal_option
8663              (g_array_event(l_event_id).array_value_num('header_index'))
8664          ,'N'
8665          ) <> 'Y'
8666    THEN
8667       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
8668          trace
8669             (p_msg      => 'Trancaction revesal option is not Y '
8670             ,p_level    => C_LEVEL_STATEMENT
8671             ,p_module   => l_log_module);
8672       END IF;
8673 
8674 --
8675 -- set the XLA_AE_JOURNAL_ENTRY_PKG.g_global_status to C_VALID (0)
8676 --
8677 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
8678 --
8679 -- set event info as cache for other routines to refer event attributes
8680 --
8681 
8682 IF l_event_id <> NVL(l_previous_event_id, -1) THEN
8683    l_previous_event_id := l_event_id;
8684 
8685    XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
8686       (p_application_id           => p_application_id
8687       ,p_primary_ledger_id        => p_primary_ledger_id
8688       ,p_base_ledger_id           => p_base_ledger_id
8689       ,p_target_ledger_id         => p_target_ledger_id
8690       ,p_entity_id                => l_array_entity_id(Idx)
8691       ,p_legal_entity_id          => l_array_legal_entity_id(Idx)
8692       ,p_entity_code              => l_array_entity_code(Idx)
8693       ,p_transaction_num          => l_array_transaction_num(Idx)
8694       ,p_event_id                 => l_array_event_id(Idx)
8695       ,p_event_class_code         => l_array_class_code(Idx)
8696       ,p_event_type_code          => l_array_event_type(Idx)
8697       ,p_event_number             => l_array_event_number(Idx)
8698       ,p_event_date               => l_array_event_date(Idx)
8699       ,p_transaction_date         => l_array_transaction_date(Idx)
8700       ,p_reference_num_1          => l_array_reference_num_1(Idx)
8701       ,p_reference_num_2          => l_array_reference_num_2(Idx)
8702       ,p_reference_num_3          => l_array_reference_num_3(Idx)
8703       ,p_reference_num_4          => l_array_reference_num_4(Idx)
8704       ,p_reference_char_1         => l_array_reference_char_1(Idx)
8705       ,p_reference_char_2         => l_array_reference_char_2(Idx)
8706       ,p_reference_char_3         => l_array_reference_char_3(Idx)
8707       ,p_reference_char_4         => l_array_reference_char_4(Idx)
8708       ,p_reference_date_1         => l_array_reference_date_1(Idx)
8709       ,p_reference_date_2         => l_array_reference_date_2(Idx)
8710       ,p_reference_date_3         => l_array_reference_date_3(Idx)
8711       ,p_reference_date_4         => l_array_reference_date_4(Idx)
8712       ,p_event_created_by         => l_array_event_created_by(Idx)
8713       ,p_budgetary_control_flag   => l_array_budgetary_control_flag(Idx));
8714        --
8715 END IF;
8716 
8717 
8718 
8719 --
8720 xla_ae_lines_pkg.SetExtractLine(p_extract_line => l_array_extract_line_num(Idx));
8721 
8722 l_acct_reversal_source := SUBSTR(NULL, 1,30);
8723 
8724 IF l_continue_with_lines THEN
8725    IF NVL(l_acct_reversal_source, 'N') NOT IN ('N','Y','B') THEN
8726       xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
8727 
8728       xla_accounting_err_pkg.build_message
8729          (p_appli_s_name            => 'XLA'
8730          ,p_msg_name                => 'XLA_AP_INVALID_REVERSAL_OPTION'
8731          ,p_token_1                 => 'LINE_NUMBER'
8732          ,p_value_1                 => l_array_extract_line_num(Idx)
8733          ,p_token_2                 => 'PRODUCT_NAME'
8734          ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
8735          ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
8736          ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
8737          ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
8738 
8739    ELSIF NVL(l_acct_reversal_source, 'N') IN ('Y','B') THEN
8740       --
8741       -- following sets the accounting attributes needed to reverse
8742       -- accounting for a distributeion
8743       --
8744 
8745       --
8746       -- 5217187
8747       --
8748       l_rec_rev_acct_attrs.array_acct_attr_code(1):= 'GL_DATE';
8752       --
8749       l_rec_rev_acct_attrs.array_date_value(1) := XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(
8750                                        g_array_event(l_event_id).array_value_num('header_index'));
8751       --
8753 
8754       -- No reversal code generated
8755 
8756       xla_ae_lines_pkg.SetAcctReversalAttrs
8757          (p_event_id             => l_event_id
8758          ,p_rec_acct_attrs       => l_rec_rev_acct_attrs
8759          ,p_calculate_acctd_flag => l_calculate_acctd_flag
8760          ,p_calculate_g_l_flag   => l_calculate_g_l_flag);
8761    END IF;
8762 
8763    IF NVL(l_acct_reversal_source, 'N') IN ('N','B') THEN
8764        l_actual_flag := NULL;  l_actual_gain_loss_ref := '#####';
8765 
8766 --
8767 AcctLineType_4 (
8768  p_application_id  => p_application_id
8769  ,p_event_id     => l_event_id
8770  ,p_calculate_acctd_flag => l_calculate_acctd_flag
8771  ,p_calculate_g_l_flag => l_calculate_g_l_flag
8772  ,p_actual_flag => l_actual_flag
8773  ,p_balance_type_code => l_balance_type_code
8774  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
8775  
8776  , p_source_1 => l_array_source_1(Idx)
8777  , p_source_5 => l_array_source_5(Idx)
8778  , p_source_6 => l_array_source_6(Idx)
8779  , p_source_7 => l_array_source_7(Idx)
8780  , p_source_8 => l_array_source_8(Idx)
8781  , p_source_9 => g_array_event(l_event_id).array_value_char('source_9')
8782  , p_source_10 => l_array_source_10(Idx)
8783  , p_source_11 => l_array_source_11(Idx)
8784  );
8785 If(l_balance_type_code = 'A') THEN
8786   l_actual_gain_loss_ref := l_gain_or_loss_ref;
8787 END IF;
8788 
8789 --
8790 
8791 
8792 --
8793 AcctLineType_5 (
8794  p_application_id  => p_application_id
8795  ,p_event_id     => l_event_id
8796  ,p_calculate_acctd_flag => l_calculate_acctd_flag
8797  ,p_calculate_g_l_flag => l_calculate_g_l_flag
8798  ,p_actual_flag => l_actual_flag
8799  ,p_balance_type_code => l_balance_type_code
8800  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
8801  
8802  , p_source_1 => l_array_source_1(Idx)
8803  , p_source_5 => l_array_source_5(Idx)
8804  , p_source_7 => l_array_source_7(Idx)
8805  , p_source_8 => l_array_source_8(Idx)
8806  , p_source_9 => g_array_event(l_event_id).array_value_char('source_9')
8807  , p_source_10 => l_array_source_10(Idx)
8808  , p_source_11 => l_array_source_11(Idx)
8809  , p_source_12 => l_array_source_12(Idx)
8810  , p_source_13 => l_array_source_13(Idx)
8811  , p_source_14 => l_array_source_14(Idx)
8812  , p_source_15 => l_array_source_15(Idx)
8813  , p_source_16 => l_array_source_16(Idx)
8814  , p_source_17 => l_array_source_17(Idx)
8815  );
8816 If(l_balance_type_code = 'A') THEN
8817   l_actual_gain_loss_ref := l_gain_or_loss_ref;
8818 END IF;
8819 
8820 --
8821 
8822 
8823 --
8824 AcctLineType_6 (
8825  p_application_id  => p_application_id
8826  ,p_event_id     => l_event_id
8827  ,p_calculate_acctd_flag => l_calculate_acctd_flag
8828  ,p_calculate_g_l_flag => l_calculate_g_l_flag
8829  ,p_actual_flag => l_actual_flag
8830  ,p_balance_type_code => l_balance_type_code
8831  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
8832  
8833  , p_source_1 => l_array_source_1(Idx)
8834  , p_source_5 => l_array_source_5(Idx)
8835  , p_source_6 => l_array_source_6(Idx)
8836  , p_source_7 => l_array_source_7(Idx)
8837  , p_source_8 => l_array_source_8(Idx)
8838  , p_source_9 => g_array_event(l_event_id).array_value_char('source_9')
8839  , p_source_10 => l_array_source_10(Idx)
8840  , p_source_11 => l_array_source_11(Idx)
8841  );
8842 If(l_balance_type_code = 'A') THEN
8843   l_actual_gain_loss_ref := l_gain_or_loss_ref;
8844 END IF;
8845 
8846 --
8847 
8848 
8849 --
8850 AcctLineType_7 (
8851  p_application_id  => p_application_id
8852  ,p_event_id     => l_event_id
8853  ,p_calculate_acctd_flag => l_calculate_acctd_flag
8854  ,p_calculate_g_l_flag => l_calculate_g_l_flag
8855  ,p_actual_flag => l_actual_flag
8856  ,p_balance_type_code => l_balance_type_code
8857  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
8858  
8859  , p_source_1 => l_array_source_1(Idx)
8860  , p_source_5 => l_array_source_5(Idx)
8861  , p_source_7 => l_array_source_7(Idx)
8862  , p_source_8 => l_array_source_8(Idx)
8863  , p_source_9 => g_array_event(l_event_id).array_value_char('source_9')
8864  , p_source_10 => l_array_source_10(Idx)
8865  , p_source_11 => l_array_source_11(Idx)
8866  , p_source_12 => l_array_source_12(Idx)
8867  );
8868 If(l_balance_type_code = 'A') THEN
8869   l_actual_gain_loss_ref := l_gain_or_loss_ref;
8870 END IF;
8871 
8872 --
8873 
8874       -- only execute it if calculate g/l flag is yes, and primary or secondary ledger
8875       -- or secondary ledger that has different currency with primary
8876       -- or alc that is calculated by sla
8877       IF (((l_calculate_g_l_flag = 'Y' AND XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_category_code <> 'ALC') or
8878             (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_category_code in ('ALC', 'SECONDARY') AND XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.calculate_amts_flag='Y'))
8879 
8880 --      IF((l_calculate_g_l_flag='Y' or XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id <>
8881 --                    XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id)
8882           AND (l_actual_flag = 'A')) THEN
8883         XLA_AE_LINES_PKG.CreateGainOrLossLines(
8884           p_event_id         => xla_ae_journal_entry_pkg.g_cache_event.event_id
8885          ,p_application_id   => p_application_id
8889          ,p_event_type_code  => C_EVENT_TYPE_CODE
8886          ,p_amb_context_code => 'DEFAULT'
8887          ,p_entity_code      => xla_ae_journal_entry_pkg.g_cache_event.entity_code
8888          ,p_event_class_code => C_EVENT_CLASS_CODE
8890          
8891          ,p_gain_ccid        => -1
8892          ,p_loss_ccid        => -1
8893 
8894          ,p_actual_flag      => l_actual_flag
8895          ,p_enc_flag         => null
8896          ,p_actual_g_l_ref   => l_actual_gain_loss_ref
8897          ,p_enc_g_l_ref      => null
8898          );
8899       END IF;
8900    END IF;
8901 END IF;
8902 
8903    ELSE
8904       --
8905       -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
8906       --
8907       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
8908          trace
8909             (p_msg      => 'Trancaction revesal option is Y'
8910             ,p_level    => C_LEVEL_STATEMENT
8911             ,p_module   => l_log_module);
8912       END IF;
8913    END IF;
8914 
8915 END LOOP;
8916 l_result := XLA_AE_LINES_PKG.InsertLines ;
8917 end loop;
8918 close line_cur;
8919 
8920 
8921 --
8922 -- insert headers into xla_ae_headers_gt table
8923 --
8924 l_result := XLA_AE_HEADER_PKG.InsertHeaders ;
8925 
8926 -- insert into errors table here.
8927 
8928 END LOOP;
8929 
8930 --
8931 -- 4865292
8932 --
8933 -- Compare g_hdr_extract_count with event count in
8934 -- CreateHeadersAndLines.
8935 --
8936 g_hdr_extract_count := g_hdr_extract_count + header_cur%ROWCOUNT;
8937 
8938 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
8939    trace (p_msg     => '# rows extracted from header extract objects '
8940                     || ' (running total): '
8941                     || g_hdr_extract_count
8942          ,p_level   => C_LEVEL_STATEMENT
8943          ,p_module  => l_log_module);
8944 END IF;
8945 
8946 CLOSE header_cur;
8947 --
8948 
8949 --
8950 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
8951    trace
8952       (p_msg      => 'END of EventClass_18'
8953       ,p_level    => C_LEVEL_PROCEDURE
8954       ,p_module   => l_log_module);
8955 END IF;
8956 --
8957 RETURN l_result;
8958 EXCEPTION
8959 WHEN xla_exceptions_pkg.application_exception THEN
8960    
8961 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
8962 
8963    
8964 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
8965 
8966    RAISE;
8967 WHEN OTHERS THEN
8968    xla_exceptions_pkg.raise_message
8969       (p_location => 'XLA_08407_AAD_S_000013_BC_PKG.EventClass_18');
8970 END EventClass_18;
8971 --
8972 
8973 ---------------------------------------
8974 --
8975 -- PRIVATE PROCEDURE
8976 --         insert_sources_19
8977 --
8978 ----------------------------------------
8979 --
8980 PROCEDURE insert_sources_19(
8981                                 p_target_ledger_id       IN NUMBER
8982                               , p_language               IN VARCHAR2
8983                               , p_sla_ledger_id          IN NUMBER
8984                               , p_pad_start_date         IN DATE
8985                               , p_pad_end_date           IN DATE
8986                          )
8987 IS
8988 
8989 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'CC_CONTRACT_PRO_ALL';
8990 C_EVENT_CLASS_CODE   CONSTANT  VARCHAR2(30) := 'CC_CONTRACT_PRO';
8991 p_apps_owner                   VARCHAR2(30);
8992 l_log_module                   VARCHAR2(240);
8993 BEGIN
8994 IF g_log_enabled THEN
8995       l_log_module := C_DEFAULT_MODULE||'.insert_sources_19';
8996 END IF;
8997 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
8998 
8999       trace
9000          (p_msg      => 'BEGIN of insert_sources_19'
9001          ,p_level    => C_LEVEL_PROCEDURE
9002          ,p_module   => l_log_module);
9003 
9004 END IF;
9005 
9006 -- select APPS owner
9007 SELECT oracle_username
9008   INTO p_apps_owner
9009   FROM fnd_oracle_userid
9010  WHERE read_only_flag = 'U'
9011 ;
9012 
9013 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
9014       trace
9015          (p_msg      => 'p_target_ledger_id = '||p_target_ledger_id||
9016                         ' - p_language = '||p_language||
9017                         ' - p_sla_ledger_id  = '||p_sla_ledger_id ||
9018                         ' - p_pad_start_date = '||TO_CHAR(p_pad_start_date)||
9019                         ' - p_pad_end_date = '||TO_CHAR(p_pad_end_date)||
9020                         ' - p_apps_owner = '||TO_CHAR(p_apps_owner)
9021          ,p_level    => C_LEVEL_STATEMENT
9022          ,p_module   => l_log_module);
9023 END IF;
9024 
9025 
9026 --
9027 INSERT INTO xla_diag_sources --hdr2
9028 (
9029         event_id
9030       , ledger_id
9031       , sla_ledger_id
9032       , description_language
9033       , object_name
9034       , object_type_code
9035       , line_number
9036       , source_application_id
9037       , source_type_code
9038       , source_code
9039       , source_value
9040       , source_meaning
9041       , created_by
9042       , creation_date
9043       , last_update_date
9044       , last_updated_by
9045       , last_update_login
9046       , program_update_date
9047       , program_application_id
9051 SELECT
9048       , program_id
9049       , request_id
9050 )
9052         event_id
9053       , p_target_ledger_id
9054       , p_sla_ledger_id
9055       , p_language
9056       , object_name
9057       , object_type_code
9058       , line_number
9059       , source_application_id
9060       , source_type_code
9061       , source_code
9062       , SUBSTR(source_value ,1,1996)
9063       , SUBSTR(source_meaning ,1,200)
9064       , xla_environment_pkg.g_Usr_Id
9065       , TRUNC(SYSDATE)
9066       , TRUNC(SYSDATE)
9067       , xla_environment_pkg.g_Usr_Id
9068       , xla_environment_pkg.g_Login_Id
9069       , TRUNC(SYSDATE)
9070       , xla_environment_pkg.g_Prog_Appl_Id
9071       , xla_environment_pkg.g_Prog_Id
9072       , xla_environment_pkg.g_Req_Id
9073   FROM (
9074        SELECT xet.event_id                  event_id
9075             , 0                          line_number
9076             , CASE r
9077                WHEN 1 THEN 'IGC_CC_EVENT_JE_HEADER_V' 
9078                 WHEN 2 THEN 'IGC_CC_EVENT_JE_HEADER_V' 
9079                 WHEN 3 THEN 'IGC_CC_EVENT_JE_HEADER_V' 
9080                 WHEN 4 THEN 'IGC_CC_EVENT_JE_HEADER_V' 
9081                 WHEN 5 THEN 'IGC_CC_EVENT_JE_HEADER_V' 
9082                 
9083                ELSE null
9084               END                           object_name
9085             , CASE r
9086                 WHEN 1 THEN 'HEADER' 
9087                 WHEN 2 THEN 'HEADER' 
9088                 WHEN 3 THEN 'HEADER' 
9089                 WHEN 4 THEN 'HEADER' 
9090                 WHEN 5 THEN 'HEADER' 
9091                 
9092                 ELSE null
9093               END                           object_type_code
9094             , CASE r
9095                 WHEN 1 THEN '8407' 
9096                 WHEN 2 THEN '8407' 
9097                 WHEN 3 THEN '8407' 
9098                 WHEN 4 THEN '8407' 
9099                 WHEN 5 THEN '8407' 
9100                 
9101                 ELSE null
9102               END                           source_application_id
9103             , 'S'             source_type_code
9104             , CASE r
9105                 WHEN 1 THEN 'HEADER_DESC' 
9106                 WHEN 2 THEN 'REFERENCE_4' 
9107                 WHEN 3 THEN 'REFERENCE_3' 
9108                 WHEN 4 THEN 'DOCUMENT_TYPE' 
9109                 WHEN 5 THEN 'ACCOUNTING_DATE' 
9110                 
9111                 ELSE null
9112               END                           source_code
9113             , CASE r
9114                 WHEN 1 THEN TO_CHAR(h1.HEADER_DESC)
9115                 WHEN 2 THEN TO_CHAR(h1.REFERENCE_4)
9116                 WHEN 3 THEN TO_CHAR(h1.REFERENCE_3)
9117                 WHEN 4 THEN TO_CHAR(h1.DOCUMENT_TYPE)
9118                 WHEN 5 THEN TO_CHAR(h1.ACCOUNTING_DATE)
9119                 
9120                 ELSE null
9121               END                           source_value
9122             , null              source_meaning
9123          FROM xla_events_gt     xet  
9124       , IGC_CC_EVENT_JE_HEADER_V  h1
9125              ,(select rownum r from all_objects where rownum <= 5 and owner = p_apps_owner)
9126          WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
9127            AND xet.event_class_code = C_EVENT_CLASS_CODE
9128               AND h1.event_id = xet.event_id
9129 
9130 )
9131 ;
9132 --
9133 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
9134 
9135       trace
9136          (p_msg      => 'number of header sources inserted = '||SQL%ROWCOUNT
9137          ,p_level    => C_LEVEL_STATEMENT
9138          ,p_module   => l_log_module);
9139 
9140 END IF;
9141 --
9142 
9143 
9144 
9145 --
9146 INSERT INTO xla_diag_sources  --line2
9147 (
9148         event_id
9149       , ledger_id
9150       , sla_ledger_id
9151       , description_language
9152       , object_name
9153       , object_type_code
9154       , line_number
9155       , source_application_id
9156       , source_type_code
9157       , source_code
9158       , source_value
9159       , source_meaning
9160       , created_by
9161       , creation_date
9162       , last_update_date
9163       , last_updated_by
9164       , last_update_login
9165       , program_update_date
9166       , program_application_id
9167       , program_id
9168       , request_id
9169 )
9170 SELECT  event_id
9171       , p_target_ledger_id
9172       , p_sla_ledger_id
9173       , p_language
9174       , object_name
9175       , object_type_code
9176       , line_number
9177       , source_application_id
9178       , source_type_code
9179       , source_code
9180       , SUBSTR(source_value,1,1996)
9181       , SUBSTR(source_meaning ,1,200)
9182       , xla_environment_pkg.g_Usr_Id
9183       , TRUNC(SYSDATE)
9184       , TRUNC(SYSDATE)
9185       , xla_environment_pkg.g_Usr_Id
9186       , xla_environment_pkg.g_Login_Id
9187       , TRUNC(SYSDATE)
9188       , xla_environment_pkg.g_Prog_Appl_Id
9189       , xla_environment_pkg.g_Prog_Id
9190       , xla_environment_pkg.g_Req_Id
9191   FROM (
9192        SELECT xet.event_id                  event_id
9193             , l2.line_number                 line_number
9194             , CASE r
9198                 WHEN 4 THEN 'IGC_CC_EVENT_JE_LINES_V' 
9195                WHEN 1 THEN 'IGC_CC_EVENT_JE_LINES_V' 
9196                 WHEN 2 THEN 'IGC_CC_EVENT_JE_LINES_V' 
9197                 WHEN 3 THEN 'IGC_CC_EVENT_JE_LINES_V' 
9199                 WHEN 5 THEN 'IGC_CC_EVENT_JE_LINES_V' 
9200                 WHEN 6 THEN 'IGC_CC_EVENT_JE_LINES_V' 
9201                 WHEN 7 THEN 'IGC_CC_EVENT_JE_LINES_V' 
9202                 WHEN 8 THEN 'IGC_CC_EVENT_JE_LINES_V' 
9203                 
9204                ELSE null
9205               END                           object_name
9206             , CASE r
9207                 WHEN 1 THEN 'LINE' 
9208                 WHEN 2 THEN 'LINE' 
9209                 WHEN 3 THEN 'LINE' 
9210                 WHEN 4 THEN 'LINE' 
9211                 WHEN 5 THEN 'LINE' 
9212                 WHEN 6 THEN 'LINE' 
9213                 WHEN 7 THEN 'LINE' 
9214                 WHEN 8 THEN 'LINE' 
9215                 
9216                 ELSE null
9217               END                           object_type_code
9218             , CASE r
9219                 WHEN 1 THEN '8407' 
9220                 WHEN 2 THEN '8407' 
9221                 WHEN 3 THEN '8407' 
9222                 WHEN 4 THEN '8407' 
9223                 WHEN 5 THEN '8407' 
9224                 WHEN 6 THEN '8407' 
9225                 WHEN 7 THEN '8407' 
9226                 WHEN 8 THEN '8407' 
9227                 
9228                 ELSE null
9229               END                           source_application_id
9230             , 'S'             source_type_code
9231             , CASE r
9232                 WHEN 1 THEN 'TRANSACTION_DESCRIPTION' 
9233                 WHEN 2 THEN 'CODE_COMBINATION_ID' 
9234                 WHEN 3 THEN 'CC_FUNC_CR_AMT' 
9235                 WHEN 4 THEN 'PROJECT_LINE' 
9236                 WHEN 5 THEN 'CC_ACCT_LINE_ID' 
9237                 WHEN 6 THEN 'CC_FUNC_AMT' 
9238                 WHEN 7 THEN 'CURRENCY_CODE' 
9239                 WHEN 8 THEN 'CC_FUNC_DR_AMT' 
9240                 
9241                 ELSE null
9242               END                           source_code
9243             , CASE r
9244                 WHEN 1 THEN TO_CHAR(l2.TRANSACTION_DESCRIPTION)
9245                 WHEN 2 THEN TO_CHAR(l2.CODE_COMBINATION_ID)
9246                 WHEN 3 THEN TO_CHAR(l2.CC_FUNC_CR_AMT)
9247                 WHEN 4 THEN TO_CHAR(l2.PROJECT_LINE)
9248                 WHEN 5 THEN TO_CHAR(l2.CC_ACCT_LINE_ID)
9249                 WHEN 6 THEN TO_CHAR(l2.CC_FUNC_AMT)
9250                 WHEN 7 THEN TO_CHAR(l2.CURRENCY_CODE)
9251                 WHEN 8 THEN TO_CHAR(l2.CC_FUNC_DR_AMT)
9252                 
9253                 ELSE null
9254               END                           source_value
9255             , null              source_meaning
9256          FROM  xla_events_gt     xet  
9257         , IGC_CC_EVENT_JE_LINES_V  l2
9258             , (select rownum r from all_objects where rownum <= 8 and owner = p_apps_owner)
9259         WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
9260           AND xet.event_class_code = C_EVENT_CLASS_CODE
9261             AND l2.event_id          = xet.event_id
9262 
9263 )
9264 ;
9265 --
9266 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
9267 
9268       trace
9269          (p_msg      => 'number of line sources inserted = '||SQL%ROWCOUNT
9270          ,p_level    => C_LEVEL_STATEMENT
9271          ,p_module   => l_log_module);
9272 
9273 END IF;
9274 
9275 
9276 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
9277       trace
9278          (p_msg      => 'END of insert_sources_19'
9279          ,p_level    => C_LEVEL_PROCEDURE
9280          ,p_module   => l_log_module);
9281 END IF;
9282 EXCEPTION
9283   WHEN xla_exceptions_pkg.application_exception THEN
9284       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
9285             trace
9286                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
9287                ,p_level    => C_LEVEL_EXCEPTION
9288                ,p_module   => l_log_module);
9289       END IF;
9290       RAISE;
9291   WHEN OTHERS THEN
9292       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
9293             trace
9294                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
9295                ,p_level    => C_LEVEL_EXCEPTION
9296                ,p_module   => l_log_module);
9297        END IF;
9298        xla_exceptions_pkg.raise_message
9299            (p_location => 'XLA_08407_AAD_S_000013_BC_PKG.insert_sources_19');
9300 END insert_sources_19;
9301 --
9302 
9303 ---------------------------------------
9304 --
9305 -- PRIVATE FUNCTION
9306 --         EventClass_19
9307 --
9308 ----------------------------------------
9309 --
9310 FUNCTION EventClass_19
9311        (p_application_id         IN NUMBER
9312        ,p_base_ledger_id         IN NUMBER
9313        ,p_target_ledger_id       IN NUMBER
9314        ,p_language               IN VARCHAR2
9315        ,p_currency_code          IN VARCHAR2
9316        ,p_sla_ledger_id          IN NUMBER
9317        ,p_pad_start_date         IN DATE
9318        ,p_pad_end_date           IN DATE
9319        ,p_primary_ledger_id      IN NUMBER)
9320 RETURN BOOLEAN IS
9321 --
9322 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'CC_CONTRACT_PRO_ALL';
9323 C_EVENT_CLASS_CODE    CONSTANT  VARCHAR2(30) := 'CC_CONTRACT_PRO';
9324 
9328 l_array_legal_entity_id                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
9325 l_calculate_acctd_flag   VARCHAR2(1) :='N';
9326 l_calculate_g_l_flag     VARCHAR2(1) :='N';
9327 --
9329 l_array_entity_id                      XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
9330 l_array_entity_code                    XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
9331 l_array_transaction_num                XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
9332 l_array_event_id                       XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
9333 l_array_class_code                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
9334 l_array_event_type                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
9335 l_array_event_number                   XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
9336 l_array_event_date                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
9337 l_array_transaction_date               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
9338 l_array_reference_num_1                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
9339 l_array_reference_num_2                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
9340 l_array_reference_num_3                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
9341 l_array_reference_num_4                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
9342 l_array_reference_char_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
9343 l_array_reference_char_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
9344 l_array_reference_char_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
9345 l_array_reference_char_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
9346 l_array_reference_date_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
9347 l_array_reference_date_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
9348 l_array_reference_date_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
9349 l_array_reference_date_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
9350 l_array_event_created_by               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V100L;
9351 l_array_budgetary_control_flag         XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
9352 
9353 l_event_id                             NUMBER;
9354 l_previous_event_id                    NUMBER;
9355 l_first_event_id                       NUMBER;
9356 l_last_event_id                        NUMBER;
9357 
9358 l_rec_acct_attrs                       XLA_AE_HEADER_PKG.t_rec_acct_attrs;
9359 l_rec_rev_acct_attrs                   XLA_AE_LINES_PKG.t_rec_acct_attrs;
9360 --
9361 --
9362 l_result                    BOOLEAN := TRUE;
9363 l_rows                      NUMBER  := 1000;
9364 l_event_type_name           VARCHAR2(80) := 'All';
9365 l_event_class_name          VARCHAR2(80) := 'CC Contract Provisional';
9366 l_description               VARCHAR2(4000);
9367 l_transaction_reversal      NUMBER;
9368 l_ae_header_id              NUMBER;
9369 l_array_extract_line_num    xla_ae_journal_entry_pkg.t_array_Num;
9370 l_log_module                VARCHAR2(240);
9371 --
9372 l_acct_reversal_source      VARCHAR2(30);
9373 l_trx_reversal_source       VARCHAR2(30);
9374 
9375 l_continue_with_lines       BOOLEAN := TRUE;
9376 --
9377 l_acc_rev_gl_date_source    DATE;                      -- 4262811
9378 --
9379 type t_array_event_id is table of number index by binary_integer;
9380 
9381 l_rec_array_event                    t_rec_array_event;
9382 l_null_rec_array_event               t_rec_array_event;
9383 l_array_ae_header_id                 xla_number_array_type;
9384 l_actual_flag                        VARCHAR2(1) := NULL;
9385 l_actual_gain_loss_ref               VARCHAR2(30) := '#####';
9386 l_balance_type_code                  VARCHAR2(1) :=NULL;
9387 l_gain_or_loss_ref                   VARCHAR2(30) :=NULL;
9388 
9389 --
9390 TYPE t_array_lookup_meaning IS TABLE OF fnd_lookup_values.meaning%TYPE INDEX BY BINARY_INTEGER;
9391 --
9392 
9393 TYPE t_array_source_2 IS TABLE OF IGC_CC_EVENT_JE_HEADER_V.HEADER_DESC%TYPE INDEX BY BINARY_INTEGER;
9394 TYPE t_array_source_3 IS TABLE OF IGC_CC_EVENT_JE_HEADER_V.REFERENCE_4%TYPE INDEX BY BINARY_INTEGER;
9395 TYPE t_array_source_4 IS TABLE OF IGC_CC_EVENT_JE_HEADER_V.REFERENCE_3%TYPE INDEX BY BINARY_INTEGER;
9396 TYPE t_array_source_9 IS TABLE OF IGC_CC_EVENT_JE_HEADER_V.DOCUMENT_TYPE%TYPE INDEX BY BINARY_INTEGER;
9397 TYPE t_array_source_18 IS TABLE OF IGC_CC_EVENT_JE_HEADER_V.ACCOUNTING_DATE%TYPE INDEX BY BINARY_INTEGER;
9398 
9399 TYPE t_array_source_1 IS TABLE OF IGC_CC_EVENT_JE_LINES_V.TRANSACTION_DESCRIPTION%TYPE INDEX BY BINARY_INTEGER;
9400 TYPE t_array_source_5 IS TABLE OF IGC_CC_EVENT_JE_LINES_V.CODE_COMBINATION_ID%TYPE INDEX BY BINARY_INTEGER;
9401 TYPE t_array_source_6 IS TABLE OF IGC_CC_EVENT_JE_LINES_V.CC_FUNC_CR_AMT%TYPE INDEX BY BINARY_INTEGER;
9402 TYPE t_array_source_7 IS TABLE OF IGC_CC_EVENT_JE_LINES_V.PROJECT_LINE%TYPE INDEX BY BINARY_INTEGER;
9403 TYPE t_array_source_8 IS TABLE OF IGC_CC_EVENT_JE_LINES_V.CC_ACCT_LINE_ID%TYPE INDEX BY BINARY_INTEGER;
9404 TYPE t_array_source_10 IS TABLE OF IGC_CC_EVENT_JE_LINES_V.CC_FUNC_AMT%TYPE INDEX BY BINARY_INTEGER;
9405 TYPE t_array_source_11 IS TABLE OF IGC_CC_EVENT_JE_LINES_V.CURRENCY_CODE%TYPE INDEX BY BINARY_INTEGER;
9406 TYPE t_array_source_12 IS TABLE OF IGC_CC_EVENT_JE_LINES_V.CC_FUNC_DR_AMT%TYPE INDEX BY BINARY_INTEGER;
9407 
9408 l_array_source_2              t_array_source_2;
9409 l_array_source_3              t_array_source_3;
9410 l_array_source_4              t_array_source_4;
9411 l_array_source_9              t_array_source_9;
9412 l_array_source_18              t_array_source_18;
9413 
9414 l_array_source_1      t_array_source_1;
9415 l_array_source_5      t_array_source_5;
9416 l_array_source_6      t_array_source_6;
9417 l_array_source_7      t_array_source_7;
9418 l_array_source_8      t_array_source_8;
9419 l_array_source_10      t_array_source_10;
9420 l_array_source_11      t_array_source_11;
9424 CURSOR header_cur
9421 l_array_source_12      t_array_source_12;
9422 
9423 --
9425 IS
9426 SELECT /*+ leading(xet) cardinality(xet,1) */
9427 -- Event Class Code: CC_CONTRACT_PRO
9428     xet.entity_id
9429    ,xet.legal_entity_id
9430    ,xet.entity_code
9431    ,xet.transaction_number
9432    ,xet.event_id
9433    ,xet.event_class_code
9434    ,xet.event_type_code
9435    ,xet.event_number
9436    ,xet.event_date
9437    ,xet.transaction_date
9438    ,xet.reference_num_1
9439    ,xet.reference_num_2
9440    ,xet.reference_num_3
9441    ,xet.reference_num_4
9442    ,xet.reference_char_1
9443    ,xet.reference_char_2
9444    ,xet.reference_char_3
9445    ,xet.reference_char_4
9446    ,xet.reference_date_1
9447    ,xet.reference_date_2
9448    ,xet.reference_date_3
9449    ,xet.reference_date_4
9450    ,xet.event_created_by
9451    ,xet.budgetary_control_flag 
9452   , h1.HEADER_DESC    source_2
9453   , h1.REFERENCE_4    source_3
9454   , h1.REFERENCE_3    source_4
9455   , h1.DOCUMENT_TYPE    source_9
9456   , h1.ACCOUNTING_DATE    source_18
9457   FROM xla_events_gt     xet 
9458   , IGC_CC_EVENT_JE_HEADER_V  h1
9459  WHERE xet.event_date between p_pad_start_date and p_pad_end_date
9460    and xet.event_class_code = C_EVENT_CLASS_CODE
9461    and xet.event_status_code <> 'N'  AND h1.event_id = xet.event_id
9462 
9463  ORDER BY event_id
9464 ;
9465 
9466 
9467 --
9468 CURSOR line_cur (x_first_event_id    in number, x_last_event_id    in number)
9469 IS
9470 SELECT  /*+ leading(xet) cardinality(xet,1) */
9471 -- Event Class Code: CC_CONTRACT_PRO
9472     xet.entity_id
9473    ,xet.legal_entity_id
9474    ,xet.entity_code
9475    ,xet.transaction_number
9476    ,xet.event_id
9477    ,xet.event_class_code
9478    ,xet.event_type_code
9479    ,xet.event_number
9480    ,xet.event_date
9481    ,xet.transaction_date
9482    ,xet.reference_num_1
9483    ,xet.reference_num_2
9484    ,xet.reference_num_3
9485    ,xet.reference_num_4
9486    ,xet.reference_char_1
9487    ,xet.reference_char_2
9488    ,xet.reference_char_3
9489    ,xet.reference_char_4
9490    ,xet.reference_date_1
9491    ,xet.reference_date_2
9492    ,xet.reference_date_3
9493    ,xet.reference_date_4
9494    ,xet.event_created_by
9495    ,xet.budgetary_control_flag
9496  , l2.LINE_NUMBER  
9497   , l2.TRANSACTION_DESCRIPTION    source_1
9498   , l2.CODE_COMBINATION_ID    source_5
9499   , l2.CC_FUNC_CR_AMT    source_6
9500   , l2.PROJECT_LINE    source_7
9501   , l2.CC_ACCT_LINE_ID    source_8
9502   , l2.CC_FUNC_AMT    source_10
9503   , l2.CURRENCY_CODE    source_11
9504   , l2.CC_FUNC_DR_AMT    source_12
9505   FROM xla_events_gt     xet 
9506   , IGC_CC_EVENT_JE_LINES_V  l2
9507  WHERE xet.event_id between x_first_event_id and x_last_event_id
9508    and xet.event_date between p_pad_start_date and p_pad_end_date
9509    and xet.event_class_code = C_EVENT_CLASS_CODE
9510    and xet.event_status_code <> 'N'   AND l2.event_id      = xet.event_id
9511 ;
9512 
9513 --
9514 BEGIN
9515 IF g_log_enabled THEN
9516    l_log_module := C_DEFAULT_MODULE||'.EventClass_19';
9517 END IF;
9518 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
9519    trace
9520       (p_msg      => 'BEGIN of EventClass_19'
9521       ,p_level    => C_LEVEL_PROCEDURE
9522       ,p_module   => l_log_module);
9523 END IF;
9524 
9525 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
9526    trace
9527       (p_msg      => 'p_application_id = '||p_application_id||
9528                      ' - p_base_ledger_id = '||p_base_ledger_id||
9529                      ' - p_target_ledger_id  = '||p_target_ledger_id||
9530                      ' - p_language = '||p_language||
9531                      ' - p_currency_code = '||p_currency_code||
9532                      ' - p_sla_ledger_id = '||p_sla_ledger_id
9533       ,p_level    => C_LEVEL_STATEMENT
9534       ,p_module   => l_log_module);
9535 END IF;
9536 --
9537 -- initialze arrays
9538 --
9539 g_array_event.DELETE;
9540 l_rec_array_event := l_null_rec_array_event;
9541 --
9542 --------------------------------------
9543 -- 4262811 Initialze MPA Line Number
9544 --------------------------------------
9545 XLA_AE_HEADER_PKG.g_mpa_line_num := 0;
9546 
9547 --
9548 
9549 --
9550 OPEN header_cur;
9551 --
9552 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
9553    trace
9554    (p_msg      => 'SQL - FETCH header_cur'
9555    ,p_level    => C_LEVEL_STATEMENT
9556    ,p_module   => l_log_module);
9557 END IF;
9558 --
9559 LOOP
9560 FETCH header_cur BULK COLLECT INTO
9561         l_array_entity_id
9562       , l_array_legal_entity_id
9563       , l_array_entity_code
9564       , l_array_transaction_num
9565       , l_array_event_id
9566       , l_array_class_code
9567       , l_array_event_type
9568       , l_array_event_number
9569       , l_array_event_date
9570       , l_array_transaction_date
9571       , l_array_reference_num_1
9572       , l_array_reference_num_2
9573       , l_array_reference_num_3
9574       , l_array_reference_num_4
9575       , l_array_reference_char_1
9576       , l_array_reference_char_2
9577       , l_array_reference_char_3
9578       , l_array_reference_char_4
9579       , l_array_reference_date_1
9583       , l_array_event_created_by
9580       , l_array_reference_date_2
9581       , l_array_reference_date_3
9582       , l_array_reference_date_4
9584       , l_array_budgetary_control_flag 
9585       , l_array_source_2
9586       , l_array_source_3
9587       , l_array_source_4
9588       , l_array_source_9
9589       , l_array_source_18
9590       LIMIT l_rows;
9591 --
9592 IF (C_LEVEL_EVENT >= g_log_level) THEN
9593    trace
9594    (p_msg      => '# rows extracted from header extract objects = '||TO_CHAR(header_cur%ROWCOUNT)
9595    ,p_level    => C_LEVEL_EVENT
9596    ,p_module   => l_log_module);
9597 END IF;
9598 --
9599 EXIT WHEN l_array_entity_id.COUNT = 0;
9600 
9601 -- initialize arrays
9602 XLA_AE_HEADER_PKG.g_rec_header_new        := NULL;
9603 XLA_AE_LINES_PKG.g_rec_lines              := NULL;
9604 
9605 --
9606 -- Bug 4458708
9607 --
9608 XLA_AE_LINES_PKG.g_LineNumber := 0;
9609 
9610 
9611 -- 4262811 - when creating Accrual Reversal or MPA, use g_last_hdr_idx to increment for next header id
9612 g_last_hdr_idx := l_array_event_id.LAST;
9613 --
9614 -- loop for the headers. Each iteration is for each header extract row
9615 -- fetched in header cursor
9616 --
9617 FOR hdr_idx IN l_array_event_id.FIRST .. l_array_event_id.LAST LOOP
9618 
9619 --
9620 -- set event info as cache for other routines to refer event attributes
9621 --
9622 XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
9623    (p_application_id           => p_application_id
9624    ,p_primary_ledger_id        => p_primary_ledger_id
9625    ,p_base_ledger_id           => p_base_ledger_id
9626    ,p_target_ledger_id         => p_target_ledger_id
9627    ,p_entity_id                => l_array_entity_id(hdr_idx)
9628    ,p_legal_entity_id          => l_array_legal_entity_id(hdr_idx)
9629    ,p_entity_code              => l_array_entity_code(hdr_idx)
9630    ,p_transaction_num          => l_array_transaction_num(hdr_idx)
9631    ,p_event_id                 => l_array_event_id(hdr_idx)
9632    ,p_event_class_code         => l_array_class_code(hdr_idx)
9633    ,p_event_type_code          => l_array_event_type(hdr_idx)
9634    ,p_event_number             => l_array_event_number(hdr_idx)
9635    ,p_event_date               => l_array_event_date(hdr_idx)
9636    ,p_transaction_date         => l_array_transaction_date(hdr_idx)
9637    ,p_reference_num_1          => l_array_reference_num_1(hdr_idx)
9638    ,p_reference_num_2          => l_array_reference_num_2(hdr_idx)
9639    ,p_reference_num_3          => l_array_reference_num_3(hdr_idx)
9640    ,p_reference_num_4          => l_array_reference_num_4(hdr_idx)
9641    ,p_reference_char_1         => l_array_reference_char_1(hdr_idx)
9642    ,p_reference_char_2         => l_array_reference_char_2(hdr_idx)
9643    ,p_reference_char_3         => l_array_reference_char_3(hdr_idx)
9644    ,p_reference_char_4         => l_array_reference_char_4(hdr_idx)
9645    ,p_reference_date_1         => l_array_reference_date_1(hdr_idx)
9646    ,p_reference_date_2         => l_array_reference_date_2(hdr_idx)
9647    ,p_reference_date_3         => l_array_reference_date_3(hdr_idx)
9648    ,p_reference_date_4         => l_array_reference_date_4(hdr_idx)
9649    ,p_event_created_by         => l_array_event_created_by(hdr_idx)
9650    ,p_budgetary_control_flag   => l_array_budgetary_control_flag(hdr_idx));
9651 
9652 --
9653 -- set the status of entry to C_VALID (0)
9654 --
9655 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status    := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
9656 
9657 --
9658 -- initialize a row for ae header
9659 --
9660 XLA_AE_HEADER_PKG.InitHeader(hdr_idx);
9661 
9662 l_event_id := l_array_event_id(hdr_idx);
9663 
9664 --
9665 -- storing the hdr_idx for event. May be used by line cursor.
9666 --
9667 g_array_event(l_event_id).array_value_num('header_index') := hdr_idx;
9668 
9669 --
9670 -- store sources from header extract. This can be improved to
9671 -- store only those sources from header extract that may be used in lines
9672 --
9673 
9674 g_array_event(l_event_id).array_value_char('source_2') := l_array_source_2(hdr_idx);
9675 g_array_event(l_event_id).array_value_char('source_3') := l_array_source_3(hdr_idx);
9676 g_array_event(l_event_id).array_value_char('source_4') := l_array_source_4(hdr_idx);
9677 g_array_event(l_event_id).array_value_char('source_9') := l_array_source_9(hdr_idx);
9678 g_array_event(l_event_id).array_value_date('source_18') := l_array_source_18(hdr_idx);
9679 
9680 --
9681 -- initilaize the status of ae headers for diffrent balance types
9682 -- the status is initialised to C_NOT_CREATED (2)
9683 --
9684 --g_array_event(l_event_id).array_value_num('actual_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
9685 --g_array_event(l_event_id).array_value_num('budget_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
9686 --g_array_event(l_event_id).array_value_num('encumbrance_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
9687 
9688 --
9689 -- call api to validate and store accounting attributes for header
9690 --
9691 
9692 ------------------------------------------------------------
9693 -- Accrual Reversal : to get date for Standard Source (NONE)
9694 ------------------------------------------------------------
9695 l_acc_rev_gl_date_source := NULL;
9696 
9697      l_rec_acct_attrs.array_acct_attr_code(1)   := 'GL_DATE';
9698       l_rec_acct_attrs.array_date_value(1) := g_array_event(l_event_id).array_value_date('source_18');
9699 
9700 
9704 
9701 XLA_AE_HEADER_PKG.SetHdrAcctAttrs(l_rec_acct_attrs);
9702 
9703 XLA_AE_HEADER_PKG.SetJeCategoryName;
9705 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_type_code(hdr_idx)  := l_array_event_type(hdr_idx);
9706 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_id(hdr_idx)         := l_array_event_id(hdr_idx);
9707 XLA_AE_HEADER_PKG.g_rec_header_new.array_entity_id(hdr_idx)        := l_array_entity_id(hdr_idx);
9708 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_number(hdr_idx)     := l_array_event_number(hdr_idx);
9709 XLA_AE_HEADER_PKG.g_rec_header_new.array_target_ledger_id(hdr_idx) := p_target_ledger_id;
9710 
9711 
9712 --
9713 xla_ae_header_pkg.SetHdrDescription(
9714    p_description => Description_2 (
9715    p_application_id => p_application_id 
9716  , p_source_2 => g_array_event(l_event_id).array_value_char('source_2')
9717  , p_source_3 => g_array_event(l_event_id).array_value_char('source_3')
9718  , p_source_4 => g_array_event(l_event_id).array_value_char('source_4')
9719    )
9720 );
9721 --
9722 
9723 -- No header level analytical criteria
9724 
9725 --
9726 --accounting attribute enhancement, bug 3612931
9727 --
9728 l_trx_reversal_source := SUBSTR(NULL, 1,30);
9729 
9730 IF NVL(l_trx_reversal_source, 'N') NOT IN ('N','Y') THEN
9731    xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
9732 
9733    xla_accounting_err_pkg.build_message
9734       (p_appli_s_name            => 'XLA'
9735       ,p_msg_name                => 'XLA_AP_INVALID_HDR_ATTR'
9736       ,p_token_1                 => 'ACCT_ATTR_NAME'
9737       ,p_value_1                 => xla_ae_sources_pkg.GetAccountingSourceName('TRX_ACCT_REVERSAL_OPTION')
9738       ,p_token_2                 => 'PRODUCT_NAME'
9739       ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
9740       ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
9741       ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
9742       ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
9743 
9744 ELSIF NVL(l_trx_reversal_source, 'N') = 'Y' THEN
9745    --
9746    -- following sets the accounting attributes needed to reverse
9747    -- accounting for a distributeion
9748    --
9749    xla_ae_lines_pkg.SetTrxReversalAttrs
9750       (p_event_id              => l_event_id
9751       ,p_gl_date               => XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(hdr_idx)
9752       ,p_trx_reversal_source   => l_trx_reversal_source);
9753 
9754 END IF;
9755 
9756 
9757 ----------------------------------------------------------------
9758 -- 4262811 -  update the header statuses to invalid in need be
9759 ----------------------------------------------------------------
9760 --
9761 XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus (p_hdr_idx => hdr_idx);
9762 
9763 
9764   -----------------------------------------------
9765   -- No accrual reversal for the event class/type
9766   -----------------------------------------------
9767 ----------------------------------------------------------------
9768 
9769 --
9770 -- this ends the header loop iteration for one bulk fetch
9771 --
9772 END LOOP;
9773 
9774 l_first_event_id   := l_array_event_id(l_array_event_id.FIRST);
9775 l_last_event_id    := l_array_event_id(l_array_event_id.LAST);
9776 
9777 --
9778 -- insert dummy rows into lines gt table that were created due to
9779 -- transaction reversals
9780 --
9781 IF XLA_AE_LINES_PKG.g_rec_lines.array_ae_header_id.COUNT > 0 THEN
9782    l_result := XLA_AE_LINES_PKG.InsertLines;
9783 END IF;
9784 
9785 --
9786 -- reset the temp_line_num for each set of events fetched from header
9787 -- cursor rather than doing it for each new event in line cursor
9788 -- Bug 3939231
9789 --
9790 xla_ae_lines_pkg.g_temp_line_num := 0;
9791 
9792 
9793 
9794 --
9795 OPEN line_cur(x_first_event_id  => l_first_event_id, x_last_event_id  => l_last_event_id);
9796 --
9797 --
9798 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
9799 
9800       trace
9801          (p_msg      => 'SQL - FETCH line_cur'
9802          ,p_level    => C_LEVEL_STATEMENT
9803          ,p_module   => l_log_module);
9804 
9805 END IF;
9806 --
9807 --
9808 LOOP
9809   --
9810   FETCH line_cur BULK COLLECT INTO
9811         l_array_entity_id
9812       , l_array_legal_entity_id
9813       , l_array_entity_code
9814       , l_array_transaction_num
9815       , l_array_event_id
9816       , l_array_class_code
9817       , l_array_event_type
9818       , l_array_event_number
9819       , l_array_event_date
9820       , l_array_transaction_date
9821       , l_array_reference_num_1
9822       , l_array_reference_num_2
9823       , l_array_reference_num_3
9824       , l_array_reference_num_4
9825       , l_array_reference_char_1
9826       , l_array_reference_char_2
9827       , l_array_reference_char_3
9828       , l_array_reference_char_4
9829       , l_array_reference_date_1
9830       , l_array_reference_date_2
9831       , l_array_reference_date_3
9832       , l_array_reference_date_4
9833       , l_array_event_created_by
9834       , l_array_budgetary_control_flag
9835       , l_array_extract_line_num 
9836       , l_array_source_1
9837       , l_array_source_5
9838       , l_array_source_6
9842       , l_array_source_11
9839       , l_array_source_7
9840       , l_array_source_8
9841       , l_array_source_10
9843       , l_array_source_12
9844       LIMIT l_rows;
9845 
9846   --
9847   IF (C_LEVEL_EVENT >= g_log_level) THEN
9848             trace
9849                (p_msg      => '# rows extracted from line extract objects = '||TO_CHAR(line_cur%ROWCOUNT)
9850                ,p_level    => C_LEVEL_EVENT
9851                ,p_module   => l_log_module);
9852   END IF;
9853   --
9854   EXIT WHEN l_array_entity_id.count = 0;
9855 
9856   XLA_AE_LINES_PKG.g_rec_lines := null;
9857 
9858 --
9859 -- Bug 4458708
9860 --
9861 XLA_AE_LINES_PKG.g_LineNumber := 0;
9862 --
9863 --
9864 
9865 FOR Idx IN 1..l_array_event_id.count LOOP
9866    --
9867    -- 5648433 (move l_event_id out of IF statement)  set l_event_id to be used inside IF condition
9868    --
9869    l_event_id := l_array_event_id(idx);  -- 5648433
9870 
9871    --
9872    -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
9873    --
9874 
9875    IF NVL(xla_ae_header_pkg.g_rec_header_new.array_trx_acct_reversal_option
9876              (g_array_event(l_event_id).array_value_num('header_index'))
9877          ,'N'
9878          ) <> 'Y'
9879    THEN
9880       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
9881          trace
9882             (p_msg      => 'Trancaction revesal option is not Y '
9883             ,p_level    => C_LEVEL_STATEMENT
9884             ,p_module   => l_log_module);
9885       END IF;
9886 
9887 --
9888 -- set the XLA_AE_JOURNAL_ENTRY_PKG.g_global_status to C_VALID (0)
9889 --
9890 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
9891 --
9892 -- set event info as cache for other routines to refer event attributes
9893 --
9894 
9895 IF l_event_id <> NVL(l_previous_event_id, -1) THEN
9896    l_previous_event_id := l_event_id;
9897 
9898    XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
9899       (p_application_id           => p_application_id
9900       ,p_primary_ledger_id        => p_primary_ledger_id
9901       ,p_base_ledger_id           => p_base_ledger_id
9902       ,p_target_ledger_id         => p_target_ledger_id
9903       ,p_entity_id                => l_array_entity_id(Idx)
9904       ,p_legal_entity_id          => l_array_legal_entity_id(Idx)
9905       ,p_entity_code              => l_array_entity_code(Idx)
9906       ,p_transaction_num          => l_array_transaction_num(Idx)
9907       ,p_event_id                 => l_array_event_id(Idx)
9908       ,p_event_class_code         => l_array_class_code(Idx)
9909       ,p_event_type_code          => l_array_event_type(Idx)
9910       ,p_event_number             => l_array_event_number(Idx)
9911       ,p_event_date               => l_array_event_date(Idx)
9912       ,p_transaction_date         => l_array_transaction_date(Idx)
9913       ,p_reference_num_1          => l_array_reference_num_1(Idx)
9914       ,p_reference_num_2          => l_array_reference_num_2(Idx)
9915       ,p_reference_num_3          => l_array_reference_num_3(Idx)
9916       ,p_reference_num_4          => l_array_reference_num_4(Idx)
9917       ,p_reference_char_1         => l_array_reference_char_1(Idx)
9918       ,p_reference_char_2         => l_array_reference_char_2(Idx)
9919       ,p_reference_char_3         => l_array_reference_char_3(Idx)
9920       ,p_reference_char_4         => l_array_reference_char_4(Idx)
9921       ,p_reference_date_1         => l_array_reference_date_1(Idx)
9922       ,p_reference_date_2         => l_array_reference_date_2(Idx)
9923       ,p_reference_date_3         => l_array_reference_date_3(Idx)
9924       ,p_reference_date_4         => l_array_reference_date_4(Idx)
9925       ,p_event_created_by         => l_array_event_created_by(Idx)
9926       ,p_budgetary_control_flag   => l_array_budgetary_control_flag(Idx));
9927        --
9928 END IF;
9929 
9930 
9931 
9932 --
9933 xla_ae_lines_pkg.SetExtractLine(p_extract_line => l_array_extract_line_num(Idx));
9934 
9935 l_acct_reversal_source := SUBSTR(NULL, 1,30);
9936 
9937 IF l_continue_with_lines THEN
9938    IF NVL(l_acct_reversal_source, 'N') NOT IN ('N','Y','B') THEN
9939       xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
9940 
9941       xla_accounting_err_pkg.build_message
9942          (p_appli_s_name            => 'XLA'
9943          ,p_msg_name                => 'XLA_AP_INVALID_REVERSAL_OPTION'
9944          ,p_token_1                 => 'LINE_NUMBER'
9945          ,p_value_1                 => l_array_extract_line_num(Idx)
9946          ,p_token_2                 => 'PRODUCT_NAME'
9947          ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
9948          ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
9949          ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
9950          ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
9951 
9952    ELSIF NVL(l_acct_reversal_source, 'N') IN ('Y','B') THEN
9953       --
9954       -- following sets the accounting attributes needed to reverse
9955       -- accounting for a distributeion
9956       --
9957 
9958       --
9959       -- 5217187
9960       --
9961       l_rec_rev_acct_attrs.array_acct_attr_code(1):= 'GL_DATE';
9962       l_rec_rev_acct_attrs.array_date_value(1) := XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(
9963                                        g_array_event(l_event_id).array_value_num('header_index'));
9967       -- No reversal code generated
9964       --
9965       --
9966 
9968 
9969       xla_ae_lines_pkg.SetAcctReversalAttrs
9970          (p_event_id             => l_event_id
9971          ,p_rec_acct_attrs       => l_rec_rev_acct_attrs
9972          ,p_calculate_acctd_flag => l_calculate_acctd_flag
9973          ,p_calculate_g_l_flag   => l_calculate_g_l_flag);
9974    END IF;
9975 
9976    IF NVL(l_acct_reversal_source, 'N') IN ('N','B') THEN
9977        l_actual_flag := NULL;  l_actual_gain_loss_ref := '#####';
9978 
9979 --
9980 AcctLineType_8 (
9981  p_application_id  => p_application_id
9982  ,p_event_id     => l_event_id
9983  ,p_calculate_acctd_flag => l_calculate_acctd_flag
9984  ,p_calculate_g_l_flag => l_calculate_g_l_flag
9985  ,p_actual_flag => l_actual_flag
9986  ,p_balance_type_code => l_balance_type_code
9987  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
9988  
9989  , p_source_1 => l_array_source_1(Idx)
9990  , p_source_5 => l_array_source_5(Idx)
9991  , p_source_6 => l_array_source_6(Idx)
9992  , p_source_7 => l_array_source_7(Idx)
9993  , p_source_8 => l_array_source_8(Idx)
9994  , p_source_9 => g_array_event(l_event_id).array_value_char('source_9')
9995  , p_source_10 => l_array_source_10(Idx)
9996  , p_source_11 => l_array_source_11(Idx)
9997  );
9998 If(l_balance_type_code = 'A') THEN
9999   l_actual_gain_loss_ref := l_gain_or_loss_ref;
10000 END IF;
10001 
10002 --
10003 
10004 
10005 --
10006 AcctLineType_9 (
10007  p_application_id  => p_application_id
10008  ,p_event_id     => l_event_id
10009  ,p_calculate_acctd_flag => l_calculate_acctd_flag
10010  ,p_calculate_g_l_flag => l_calculate_g_l_flag
10011  ,p_actual_flag => l_actual_flag
10012  ,p_balance_type_code => l_balance_type_code
10013  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
10014  
10015  , p_source_1 => l_array_source_1(Idx)
10016  , p_source_5 => l_array_source_5(Idx)
10017  , p_source_7 => l_array_source_7(Idx)
10018  , p_source_8 => l_array_source_8(Idx)
10019  , p_source_9 => g_array_event(l_event_id).array_value_char('source_9')
10020  , p_source_10 => l_array_source_10(Idx)
10021  , p_source_11 => l_array_source_11(Idx)
10022  , p_source_12 => l_array_source_12(Idx)
10023  );
10024 If(l_balance_type_code = 'A') THEN
10025   l_actual_gain_loss_ref := l_gain_or_loss_ref;
10026 END IF;
10027 
10028 --
10029 
10030 
10031 --
10032 AcctLineType_10 (
10033  p_application_id  => p_application_id
10034  ,p_event_id     => l_event_id
10035  ,p_calculate_acctd_flag => l_calculate_acctd_flag
10036  ,p_calculate_g_l_flag => l_calculate_g_l_flag
10037  ,p_actual_flag => l_actual_flag
10038  ,p_balance_type_code => l_balance_type_code
10039  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
10040  
10041  , p_source_1 => l_array_source_1(Idx)
10042  , p_source_5 => l_array_source_5(Idx)
10043  , p_source_6 => l_array_source_6(Idx)
10044  , p_source_7 => l_array_source_7(Idx)
10045  , p_source_8 => l_array_source_8(Idx)
10046  , p_source_9 => g_array_event(l_event_id).array_value_char('source_9')
10047  , p_source_10 => l_array_source_10(Idx)
10048  , p_source_11 => l_array_source_11(Idx)
10049  );
10050 If(l_balance_type_code = 'A') THEN
10051   l_actual_gain_loss_ref := l_gain_or_loss_ref;
10052 END IF;
10053 
10054 --
10055 
10056 
10057 --
10058 AcctLineType_11 (
10059  p_application_id  => p_application_id
10060  ,p_event_id     => l_event_id
10061  ,p_calculate_acctd_flag => l_calculate_acctd_flag
10062  ,p_calculate_g_l_flag => l_calculate_g_l_flag
10063  ,p_actual_flag => l_actual_flag
10064  ,p_balance_type_code => l_balance_type_code
10065  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
10066  
10067  , p_source_1 => l_array_source_1(Idx)
10068  , p_source_5 => l_array_source_5(Idx)
10069  , p_source_7 => l_array_source_7(Idx)
10070  , p_source_8 => l_array_source_8(Idx)
10071  , p_source_9 => g_array_event(l_event_id).array_value_char('source_9')
10072  , p_source_10 => l_array_source_10(Idx)
10073  , p_source_11 => l_array_source_11(Idx)
10074  , p_source_12 => l_array_source_12(Idx)
10075  );
10076 If(l_balance_type_code = 'A') THEN
10077   l_actual_gain_loss_ref := l_gain_or_loss_ref;
10078 END IF;
10079 
10080 --
10081 
10082       -- only execute it if calculate g/l flag is yes, and primary or secondary ledger
10083       -- or secondary ledger that has different currency with primary
10084       -- or alc that is calculated by sla
10085       IF (((l_calculate_g_l_flag = 'Y' AND XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_category_code <> 'ALC') or
10086             (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_category_code in ('ALC', 'SECONDARY') AND XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.calculate_amts_flag='Y'))
10087 
10088 --      IF((l_calculate_g_l_flag='Y' or XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id <>
10089 --                    XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id)
10090           AND (l_actual_flag = 'A')) THEN
10091         XLA_AE_LINES_PKG.CreateGainOrLossLines(
10092           p_event_id         => xla_ae_journal_entry_pkg.g_cache_event.event_id
10093          ,p_application_id   => p_application_id
10094          ,p_amb_context_code => 'DEFAULT'
10095          ,p_entity_code      => xla_ae_journal_entry_pkg.g_cache_event.entity_code
10096          ,p_event_class_code => C_EVENT_CLASS_CODE
10097          ,p_event_type_code  => C_EVENT_TYPE_CODE
10098          
10102          ,p_actual_flag      => l_actual_flag
10099          ,p_gain_ccid        => -1
10100          ,p_loss_ccid        => -1
10101 
10103          ,p_enc_flag         => null
10104          ,p_actual_g_l_ref   => l_actual_gain_loss_ref
10105          ,p_enc_g_l_ref      => null
10106          );
10107       END IF;
10108    END IF;
10109 END IF;
10110 
10111    ELSE
10112       --
10113       -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
10114       --
10115       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
10116          trace
10117             (p_msg      => 'Trancaction revesal option is Y'
10118             ,p_level    => C_LEVEL_STATEMENT
10119             ,p_module   => l_log_module);
10120       END IF;
10121    END IF;
10122 
10123 END LOOP;
10124 l_result := XLA_AE_LINES_PKG.InsertLines ;
10125 end loop;
10126 close line_cur;
10127 
10128 
10129 --
10130 -- insert headers into xla_ae_headers_gt table
10131 --
10132 l_result := XLA_AE_HEADER_PKG.InsertHeaders ;
10133 
10134 -- insert into errors table here.
10135 
10136 END LOOP;
10137 
10138 --
10139 -- 4865292
10140 --
10141 -- Compare g_hdr_extract_count with event count in
10142 -- CreateHeadersAndLines.
10143 --
10144 g_hdr_extract_count := g_hdr_extract_count + header_cur%ROWCOUNT;
10145 
10146 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
10147    trace (p_msg     => '# rows extracted from header extract objects '
10148                     || ' (running total): '
10149                     || g_hdr_extract_count
10150          ,p_level   => C_LEVEL_STATEMENT
10151          ,p_module  => l_log_module);
10152 END IF;
10153 
10154 CLOSE header_cur;
10155 --
10156 
10157 --
10158 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
10159    trace
10160       (p_msg      => 'END of EventClass_19'
10161       ,p_level    => C_LEVEL_PROCEDURE
10162       ,p_module   => l_log_module);
10163 END IF;
10164 --
10165 RETURN l_result;
10166 EXCEPTION
10167 WHEN xla_exceptions_pkg.application_exception THEN
10168    
10169 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
10170 
10171    
10172 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
10173 
10174    RAISE;
10175 WHEN OTHERS THEN
10176    xla_exceptions_pkg.raise_message
10177       (p_location => 'XLA_08407_AAD_S_000013_BC_PKG.EventClass_19');
10178 END EventClass_19;
10179 --
10180 
10181 ---------------------------------------
10182 --
10183 -- PRIVATE PROCEDURE
10184 --         insert_sources_20
10185 --
10186 ----------------------------------------
10187 --
10188 PROCEDURE insert_sources_20(
10189                                 p_target_ledger_id       IN NUMBER
10190                               , p_language               IN VARCHAR2
10191                               , p_sla_ledger_id          IN NUMBER
10192                               , p_pad_start_date         IN DATE
10193                               , p_pad_end_date           IN DATE
10194                          )
10195 IS
10196 
10197 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'CC_PROJECT_BUDGET_ALL';
10198 C_EVENT_CLASS_CODE   CONSTANT  VARCHAR2(30) := 'CC_PROJECT_BUDGET';
10199 p_apps_owner                   VARCHAR2(30);
10200 l_log_module                   VARCHAR2(240);
10201 BEGIN
10202 IF g_log_enabled THEN
10203       l_log_module := C_DEFAULT_MODULE||'.insert_sources_20';
10204 END IF;
10205 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
10206 
10207       trace
10208          (p_msg      => 'BEGIN of insert_sources_20'
10209          ,p_level    => C_LEVEL_PROCEDURE
10210          ,p_module   => l_log_module);
10211 
10212 END IF;
10213 
10214 -- select APPS owner
10215 SELECT oracle_username
10216   INTO p_apps_owner
10217   FROM fnd_oracle_userid
10218  WHERE read_only_flag = 'U'
10219 ;
10220 
10221 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
10222       trace
10223          (p_msg      => 'p_target_ledger_id = '||p_target_ledger_id||
10224                         ' - p_language = '||p_language||
10225                         ' - p_sla_ledger_id  = '||p_sla_ledger_id ||
10226                         ' - p_pad_start_date = '||TO_CHAR(p_pad_start_date)||
10227                         ' - p_pad_end_date = '||TO_CHAR(p_pad_end_date)||
10228                         ' - p_apps_owner = '||TO_CHAR(p_apps_owner)
10229          ,p_level    => C_LEVEL_STATEMENT
10230          ,p_module   => l_log_module);
10231 END IF;
10232 
10233 
10234 --
10235 INSERT INTO xla_diag_sources --hdr2
10236 (
10237         event_id
10238       , ledger_id
10239       , sla_ledger_id
10240       , description_language
10241       , object_name
10242       , object_type_code
10243       , line_number
10244       , source_application_id
10245       , source_type_code
10246       , source_code
10247       , source_value
10248       , source_meaning
10249       , created_by
10250       , creation_date
10251       , last_update_date
10252       , last_updated_by
10253       , last_update_login
10254       , program_update_date
10255       , program_application_id
10256       , program_id
10257       , request_id
10258 )
10259 SELECT
10263       , p_language
10260         event_id
10261       , p_target_ledger_id
10262       , p_sla_ledger_id
10264       , object_name
10265       , object_type_code
10266       , line_number
10267       , source_application_id
10268       , source_type_code
10269       , source_code
10270       , SUBSTR(source_value ,1,1996)
10271       , SUBSTR(source_meaning ,1,200)
10272       , xla_environment_pkg.g_Usr_Id
10273       , TRUNC(SYSDATE)
10274       , TRUNC(SYSDATE)
10275       , xla_environment_pkg.g_Usr_Id
10276       , xla_environment_pkg.g_Login_Id
10277       , TRUNC(SYSDATE)
10278       , xla_environment_pkg.g_Prog_Appl_Id
10279       , xla_environment_pkg.g_Prog_Id
10280       , xla_environment_pkg.g_Req_Id
10281   FROM (
10282        SELECT xet.event_id                  event_id
10283             , 0                          line_number
10284             , CASE r
10285                WHEN 1 THEN 'IGC_CC_EVENT_JE_HEADER_V' 
10286                 WHEN 2 THEN 'IGC_CC_EVENT_JE_HEADER_V' 
10287                 WHEN 3 THEN 'IGC_CC_EVENT_JE_HEADER_V' 
10288                 WHEN 4 THEN 'IGC_CC_EVENT_JE_HEADER_V' 
10289                 WHEN 5 THEN 'IGC_CC_EVENT_JE_HEADER_V' 
10290                 
10291                ELSE null
10292               END                           object_name
10293             , CASE r
10294                 WHEN 1 THEN 'HEADER' 
10295                 WHEN 2 THEN 'HEADER' 
10296                 WHEN 3 THEN 'HEADER' 
10297                 WHEN 4 THEN 'HEADER' 
10298                 WHEN 5 THEN 'HEADER' 
10299                 
10300                 ELSE null
10301               END                           object_type_code
10302             , CASE r
10303                 WHEN 1 THEN '8407' 
10304                 WHEN 2 THEN '8407' 
10305                 WHEN 3 THEN '8407' 
10306                 WHEN 4 THEN '8407' 
10307                 WHEN 5 THEN '8407' 
10308                 
10309                 ELSE null
10310               END                           source_application_id
10311             , 'S'             source_type_code
10312             , CASE r
10313                 WHEN 1 THEN 'HEADER_DESC' 
10314                 WHEN 2 THEN 'REFERENCE_4' 
10315                 WHEN 3 THEN 'REFERENCE_3' 
10316                 WHEN 4 THEN 'DOCUMENT_TYPE' 
10317                 WHEN 5 THEN 'ACCOUNTING_DATE' 
10318                 
10319                 ELSE null
10320               END                           source_code
10321             , CASE r
10322                 WHEN 1 THEN TO_CHAR(h1.HEADER_DESC)
10323                 WHEN 2 THEN TO_CHAR(h1.REFERENCE_4)
10324                 WHEN 3 THEN TO_CHAR(h1.REFERENCE_3)
10325                 WHEN 4 THEN TO_CHAR(h1.DOCUMENT_TYPE)
10326                 WHEN 5 THEN TO_CHAR(h1.ACCOUNTING_DATE)
10327                 
10328                 ELSE null
10329               END                           source_value
10330             , null              source_meaning
10331          FROM xla_events_gt     xet  
10332       , IGC_CC_EVENT_JE_HEADER_V  h1
10333              ,(select rownum r from all_objects where rownum <= 5 and owner = p_apps_owner)
10334          WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
10335            AND xet.event_class_code = C_EVENT_CLASS_CODE
10336               AND h1.event_id = xet.event_id
10337 
10338 )
10339 ;
10340 --
10341 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
10342 
10343       trace
10344          (p_msg      => 'number of header sources inserted = '||SQL%ROWCOUNT
10345          ,p_level    => C_LEVEL_STATEMENT
10346          ,p_module   => l_log_module);
10347 
10348 END IF;
10349 --
10350 
10351 
10352 
10353 --
10354 INSERT INTO xla_diag_sources  --line2
10355 (
10356         event_id
10357       , ledger_id
10358       , sla_ledger_id
10359       , description_language
10360       , object_name
10361       , object_type_code
10362       , line_number
10363       , source_application_id
10364       , source_type_code
10365       , source_code
10366       , source_value
10367       , source_meaning
10368       , created_by
10369       , creation_date
10370       , last_update_date
10371       , last_updated_by
10372       , last_update_login
10373       , program_update_date
10374       , program_application_id
10375       , program_id
10376       , request_id
10377 )
10378 SELECT  event_id
10379       , p_target_ledger_id
10380       , p_sla_ledger_id
10381       , p_language
10382       , object_name
10383       , object_type_code
10384       , line_number
10385       , source_application_id
10386       , source_type_code
10387       , source_code
10388       , SUBSTR(source_value,1,1996)
10389       , SUBSTR(source_meaning ,1,200)
10390       , xla_environment_pkg.g_Usr_Id
10391       , TRUNC(SYSDATE)
10392       , TRUNC(SYSDATE)
10393       , xla_environment_pkg.g_Usr_Id
10394       , xla_environment_pkg.g_Login_Id
10395       , TRUNC(SYSDATE)
10396       , xla_environment_pkg.g_Prog_Appl_Id
10397       , xla_environment_pkg.g_Prog_Id
10398       , xla_environment_pkg.g_Req_Id
10399   FROM (
10400        SELECT xet.event_id                  event_id
10401             , l2.line_number                 line_number
10402             , CASE r
10406                 WHEN 4 THEN 'IGC_CC_EVENT_JE_LINES_V' 
10403                WHEN 1 THEN 'IGC_CC_EVENT_JE_LINES_V' 
10404                 WHEN 2 THEN 'IGC_CC_EVENT_JE_LINES_V' 
10405                 WHEN 3 THEN 'IGC_CC_EVENT_JE_LINES_V' 
10407                 WHEN 5 THEN 'IGC_CC_EVENT_JE_LINES_V' 
10408                 WHEN 6 THEN 'IGC_CC_EVENT_JE_LINES_V' 
10409                 WHEN 7 THEN 'IGC_CC_EVENT_JE_LINES_V' 
10410                 
10411                ELSE null
10412               END                           object_name
10413             , CASE r
10414                 WHEN 1 THEN 'LINE' 
10415                 WHEN 2 THEN 'LINE' 
10416                 WHEN 3 THEN 'LINE' 
10417                 WHEN 4 THEN 'LINE' 
10418                 WHEN 5 THEN 'LINE' 
10419                 WHEN 6 THEN 'LINE' 
10420                 WHEN 7 THEN 'LINE' 
10421                 
10422                 ELSE null
10423               END                           object_type_code
10424             , CASE r
10425                 WHEN 1 THEN '8407' 
10426                 WHEN 2 THEN '8407' 
10427                 WHEN 3 THEN '8407' 
10428                 WHEN 4 THEN '8407' 
10429                 WHEN 5 THEN '8407' 
10430                 WHEN 6 THEN '8407' 
10431                 WHEN 7 THEN '8407' 
10432                 
10433                 ELSE null
10434               END                           source_application_id
10435             , 'S'             source_type_code
10436             , CASE r
10437                 WHEN 1 THEN 'TRANSACTION_DESCRIPTION' 
10438                 WHEN 2 THEN 'CODE_COMBINATION_ID' 
10439                 WHEN 3 THEN 'CC_FUNC_CR_AMT' 
10440                 WHEN 4 THEN 'CC_ACCT_LINE_ID' 
10441                 WHEN 5 THEN 'CC_FUNC_AMT' 
10442                 WHEN 6 THEN 'CURRENCY_CODE' 
10443                 WHEN 7 THEN 'CC_FUNC_DR_AMT' 
10444                 
10445                 ELSE null
10446               END                           source_code
10447             , CASE r
10448                 WHEN 1 THEN TO_CHAR(l2.TRANSACTION_DESCRIPTION)
10449                 WHEN 2 THEN TO_CHAR(l2.CODE_COMBINATION_ID)
10450                 WHEN 3 THEN TO_CHAR(l2.CC_FUNC_CR_AMT)
10451                 WHEN 4 THEN TO_CHAR(l2.CC_ACCT_LINE_ID)
10452                 WHEN 5 THEN TO_CHAR(l2.CC_FUNC_AMT)
10453                 WHEN 6 THEN TO_CHAR(l2.CURRENCY_CODE)
10454                 WHEN 7 THEN TO_CHAR(l2.CC_FUNC_DR_AMT)
10455                 
10456                 ELSE null
10457               END                           source_value
10458             , null              source_meaning
10459          FROM  xla_events_gt     xet  
10460         , IGC_CC_EVENT_JE_LINES_V  l2
10461             , (select rownum r from all_objects where rownum <= 7 and owner = p_apps_owner)
10462         WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
10463           AND xet.event_class_code = C_EVENT_CLASS_CODE
10464             AND l2.event_id          = xet.event_id
10465 
10466 )
10467 ;
10468 --
10469 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
10470 
10471       trace
10472          (p_msg      => 'number of line sources inserted = '||SQL%ROWCOUNT
10473          ,p_level    => C_LEVEL_STATEMENT
10474          ,p_module   => l_log_module);
10475 
10476 END IF;
10477 
10478 
10479 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
10480       trace
10481          (p_msg      => 'END of insert_sources_20'
10482          ,p_level    => C_LEVEL_PROCEDURE
10483          ,p_module   => l_log_module);
10484 END IF;
10485 EXCEPTION
10486   WHEN xla_exceptions_pkg.application_exception THEN
10487       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
10488             trace
10489                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
10490                ,p_level    => C_LEVEL_EXCEPTION
10491                ,p_module   => l_log_module);
10492       END IF;
10493       RAISE;
10494   WHEN OTHERS THEN
10495       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
10496             trace
10497                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
10498                ,p_level    => C_LEVEL_EXCEPTION
10499                ,p_module   => l_log_module);
10500        END IF;
10501        xla_exceptions_pkg.raise_message
10502            (p_location => 'XLA_08407_AAD_S_000013_BC_PKG.insert_sources_20');
10503 END insert_sources_20;
10504 --
10505 
10506 ---------------------------------------
10507 --
10508 -- PRIVATE FUNCTION
10509 --         EventClass_20
10510 --
10511 ----------------------------------------
10512 --
10513 FUNCTION EventClass_20
10514        (p_application_id         IN NUMBER
10515        ,p_base_ledger_id         IN NUMBER
10516        ,p_target_ledger_id       IN NUMBER
10517        ,p_language               IN VARCHAR2
10518        ,p_currency_code          IN VARCHAR2
10519        ,p_sla_ledger_id          IN NUMBER
10520        ,p_pad_start_date         IN DATE
10521        ,p_pad_end_date           IN DATE
10522        ,p_primary_ledger_id      IN NUMBER)
10523 RETURN BOOLEAN IS
10524 --
10525 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'CC_PROJECT_BUDGET_ALL';
10526 C_EVENT_CLASS_CODE    CONSTANT  VARCHAR2(30) := 'CC_PROJECT_BUDGET';
10527 
10528 l_calculate_acctd_flag   VARCHAR2(1) :='N';
10529 l_calculate_g_l_flag     VARCHAR2(1) :='N';
10530 --
10531 l_array_legal_entity_id                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
10532 l_array_entity_id                      XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
10536 l_array_class_code                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
10533 l_array_entity_code                    XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
10534 l_array_transaction_num                XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
10535 l_array_event_id                       XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
10537 l_array_event_type                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
10538 l_array_event_number                   XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
10539 l_array_event_date                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
10540 l_array_transaction_date               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
10541 l_array_reference_num_1                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
10542 l_array_reference_num_2                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
10543 l_array_reference_num_3                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
10544 l_array_reference_num_4                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
10545 l_array_reference_char_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
10546 l_array_reference_char_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
10547 l_array_reference_char_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
10548 l_array_reference_char_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
10549 l_array_reference_date_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
10550 l_array_reference_date_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
10551 l_array_reference_date_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
10552 l_array_reference_date_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
10553 l_array_event_created_by               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V100L;
10554 l_array_budgetary_control_flag         XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
10555 
10556 l_event_id                             NUMBER;
10557 l_previous_event_id                    NUMBER;
10558 l_first_event_id                       NUMBER;
10559 l_last_event_id                        NUMBER;
10560 
10561 l_rec_acct_attrs                       XLA_AE_HEADER_PKG.t_rec_acct_attrs;
10562 l_rec_rev_acct_attrs                   XLA_AE_LINES_PKG.t_rec_acct_attrs;
10563 --
10564 --
10565 l_result                    BOOLEAN := TRUE;
10566 l_rows                      NUMBER  := 1000;
10567 l_event_type_name           VARCHAR2(80) := 'All';
10568 l_event_class_name          VARCHAR2(80) := 'CC Project Budget';
10569 l_description               VARCHAR2(4000);
10570 l_transaction_reversal      NUMBER;
10571 l_ae_header_id              NUMBER;
10572 l_array_extract_line_num    xla_ae_journal_entry_pkg.t_array_Num;
10573 l_log_module                VARCHAR2(240);
10574 --
10575 l_acct_reversal_source      VARCHAR2(30);
10576 l_trx_reversal_source       VARCHAR2(30);
10577 
10578 l_continue_with_lines       BOOLEAN := TRUE;
10579 --
10580 l_acc_rev_gl_date_source    DATE;                      -- 4262811
10581 --
10582 type t_array_event_id is table of number index by binary_integer;
10583 
10584 l_rec_array_event                    t_rec_array_event;
10585 l_null_rec_array_event               t_rec_array_event;
10586 l_array_ae_header_id                 xla_number_array_type;
10587 l_actual_flag                        VARCHAR2(1) := NULL;
10588 l_actual_gain_loss_ref               VARCHAR2(30) := '#####';
10589 l_balance_type_code                  VARCHAR2(1) :=NULL;
10590 l_gain_or_loss_ref                   VARCHAR2(30) :=NULL;
10591 
10592 --
10593 TYPE t_array_lookup_meaning IS TABLE OF fnd_lookup_values.meaning%TYPE INDEX BY BINARY_INTEGER;
10594 --
10595 
10596 TYPE t_array_source_2 IS TABLE OF IGC_CC_EVENT_JE_HEADER_V.HEADER_DESC%TYPE INDEX BY BINARY_INTEGER;
10597 TYPE t_array_source_3 IS TABLE OF IGC_CC_EVENT_JE_HEADER_V.REFERENCE_4%TYPE INDEX BY BINARY_INTEGER;
10598 TYPE t_array_source_4 IS TABLE OF IGC_CC_EVENT_JE_HEADER_V.REFERENCE_3%TYPE INDEX BY BINARY_INTEGER;
10599 TYPE t_array_source_9 IS TABLE OF IGC_CC_EVENT_JE_HEADER_V.DOCUMENT_TYPE%TYPE INDEX BY BINARY_INTEGER;
10600 TYPE t_array_source_18 IS TABLE OF IGC_CC_EVENT_JE_HEADER_V.ACCOUNTING_DATE%TYPE INDEX BY BINARY_INTEGER;
10601 
10602 TYPE t_array_source_1 IS TABLE OF IGC_CC_EVENT_JE_LINES_V.TRANSACTION_DESCRIPTION%TYPE INDEX BY BINARY_INTEGER;
10603 TYPE t_array_source_5 IS TABLE OF IGC_CC_EVENT_JE_LINES_V.CODE_COMBINATION_ID%TYPE INDEX BY BINARY_INTEGER;
10604 TYPE t_array_source_6 IS TABLE OF IGC_CC_EVENT_JE_LINES_V.CC_FUNC_CR_AMT%TYPE INDEX BY BINARY_INTEGER;
10605 TYPE t_array_source_8 IS TABLE OF IGC_CC_EVENT_JE_LINES_V.CC_ACCT_LINE_ID%TYPE INDEX BY BINARY_INTEGER;
10606 TYPE t_array_source_10 IS TABLE OF IGC_CC_EVENT_JE_LINES_V.CC_FUNC_AMT%TYPE INDEX BY BINARY_INTEGER;
10607 TYPE t_array_source_11 IS TABLE OF IGC_CC_EVENT_JE_LINES_V.CURRENCY_CODE%TYPE INDEX BY BINARY_INTEGER;
10608 TYPE t_array_source_12 IS TABLE OF IGC_CC_EVENT_JE_LINES_V.CC_FUNC_DR_AMT%TYPE INDEX BY BINARY_INTEGER;
10609 
10610 l_array_source_2              t_array_source_2;
10611 l_array_source_3              t_array_source_3;
10612 l_array_source_4              t_array_source_4;
10613 l_array_source_9              t_array_source_9;
10614 l_array_source_18              t_array_source_18;
10615 
10616 l_array_source_1      t_array_source_1;
10617 l_array_source_5      t_array_source_5;
10618 l_array_source_6      t_array_source_6;
10619 l_array_source_8      t_array_source_8;
10620 l_array_source_10      t_array_source_10;
10621 l_array_source_11      t_array_source_11;
10622 l_array_source_12      t_array_source_12;
10623 
10624 --
10625 CURSOR header_cur
10626 IS
10627 SELECT /*+ leading(xet) cardinality(xet,1) */
10628 -- Event Class Code: CC_PROJECT_BUDGET
10629     xet.entity_id
10633    ,xet.event_id
10630    ,xet.legal_entity_id
10631    ,xet.entity_code
10632    ,xet.transaction_number
10634    ,xet.event_class_code
10635    ,xet.event_type_code
10636    ,xet.event_number
10637    ,xet.event_date
10638    ,xet.transaction_date
10639    ,xet.reference_num_1
10640    ,xet.reference_num_2
10641    ,xet.reference_num_3
10642    ,xet.reference_num_4
10643    ,xet.reference_char_1
10644    ,xet.reference_char_2
10645    ,xet.reference_char_3
10646    ,xet.reference_char_4
10647    ,xet.reference_date_1
10648    ,xet.reference_date_2
10649    ,xet.reference_date_3
10650    ,xet.reference_date_4
10651    ,xet.event_created_by
10652    ,xet.budgetary_control_flag 
10653   , h1.HEADER_DESC    source_2
10654   , h1.REFERENCE_4    source_3
10655   , h1.REFERENCE_3    source_4
10656   , h1.DOCUMENT_TYPE    source_9
10657   , h1.ACCOUNTING_DATE    source_18
10658   FROM xla_events_gt     xet 
10659   , IGC_CC_EVENT_JE_HEADER_V  h1
10660  WHERE xet.event_date between p_pad_start_date and p_pad_end_date
10661    and xet.event_class_code = C_EVENT_CLASS_CODE
10662    and xet.event_status_code <> 'N'  AND h1.event_id = xet.event_id
10663 
10664  ORDER BY event_id
10665 ;
10666 
10667 
10668 --
10669 CURSOR line_cur (x_first_event_id    in number, x_last_event_id    in number)
10670 IS
10671 SELECT  /*+ leading(xet) cardinality(xet,1) */
10672 -- Event Class Code: CC_PROJECT_BUDGET
10673     xet.entity_id
10674    ,xet.legal_entity_id
10675    ,xet.entity_code
10676    ,xet.transaction_number
10677    ,xet.event_id
10678    ,xet.event_class_code
10679    ,xet.event_type_code
10680    ,xet.event_number
10681    ,xet.event_date
10682    ,xet.transaction_date
10683    ,xet.reference_num_1
10684    ,xet.reference_num_2
10685    ,xet.reference_num_3
10686    ,xet.reference_num_4
10687    ,xet.reference_char_1
10688    ,xet.reference_char_2
10689    ,xet.reference_char_3
10690    ,xet.reference_char_4
10691    ,xet.reference_date_1
10692    ,xet.reference_date_2
10693    ,xet.reference_date_3
10694    ,xet.reference_date_4
10695    ,xet.event_created_by
10696    ,xet.budgetary_control_flag
10697  , l2.LINE_NUMBER  
10698   , l2.TRANSACTION_DESCRIPTION    source_1
10699   , l2.CODE_COMBINATION_ID    source_5
10700   , l2.CC_FUNC_CR_AMT    source_6
10701   , l2.CC_ACCT_LINE_ID    source_8
10702   , l2.CC_FUNC_AMT    source_10
10703   , l2.CURRENCY_CODE    source_11
10704   , l2.CC_FUNC_DR_AMT    source_12
10705   FROM xla_events_gt     xet 
10706   , IGC_CC_EVENT_JE_LINES_V  l2
10707  WHERE xet.event_id between x_first_event_id and x_last_event_id
10708    and xet.event_date between p_pad_start_date and p_pad_end_date
10709    and xet.event_class_code = C_EVENT_CLASS_CODE
10710    and xet.event_status_code <> 'N'   AND l2.event_id      = xet.event_id
10711 ;
10712 
10713 --
10714 BEGIN
10715 IF g_log_enabled THEN
10716    l_log_module := C_DEFAULT_MODULE||'.EventClass_20';
10717 END IF;
10718 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
10719    trace
10720       (p_msg      => 'BEGIN of EventClass_20'
10721       ,p_level    => C_LEVEL_PROCEDURE
10722       ,p_module   => l_log_module);
10723 END IF;
10724 
10725 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
10726    trace
10727       (p_msg      => 'p_application_id = '||p_application_id||
10728                      ' - p_base_ledger_id = '||p_base_ledger_id||
10729                      ' - p_target_ledger_id  = '||p_target_ledger_id||
10730                      ' - p_language = '||p_language||
10731                      ' - p_currency_code = '||p_currency_code||
10732                      ' - p_sla_ledger_id = '||p_sla_ledger_id
10733       ,p_level    => C_LEVEL_STATEMENT
10734       ,p_module   => l_log_module);
10735 END IF;
10736 --
10737 -- initialze arrays
10738 --
10739 g_array_event.DELETE;
10740 l_rec_array_event := l_null_rec_array_event;
10741 --
10742 --------------------------------------
10743 -- 4262811 Initialze MPA Line Number
10744 --------------------------------------
10745 XLA_AE_HEADER_PKG.g_mpa_line_num := 0;
10746 
10747 --
10748 
10749 --
10750 OPEN header_cur;
10751 --
10752 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
10753    trace
10754    (p_msg      => 'SQL - FETCH header_cur'
10755    ,p_level    => C_LEVEL_STATEMENT
10756    ,p_module   => l_log_module);
10757 END IF;
10758 --
10759 LOOP
10760 FETCH header_cur BULK COLLECT INTO
10761         l_array_entity_id
10762       , l_array_legal_entity_id
10763       , l_array_entity_code
10764       , l_array_transaction_num
10765       , l_array_event_id
10766       , l_array_class_code
10767       , l_array_event_type
10768       , l_array_event_number
10769       , l_array_event_date
10770       , l_array_transaction_date
10771       , l_array_reference_num_1
10772       , l_array_reference_num_2
10773       , l_array_reference_num_3
10774       , l_array_reference_num_4
10775       , l_array_reference_char_1
10776       , l_array_reference_char_2
10777       , l_array_reference_char_3
10778       , l_array_reference_char_4
10779       , l_array_reference_date_1
10780       , l_array_reference_date_2
10781       , l_array_reference_date_3
10785       , l_array_source_2
10782       , l_array_reference_date_4
10783       , l_array_event_created_by
10784       , l_array_budgetary_control_flag 
10786       , l_array_source_3
10787       , l_array_source_4
10788       , l_array_source_9
10789       , l_array_source_18
10790       LIMIT l_rows;
10791 --
10792 IF (C_LEVEL_EVENT >= g_log_level) THEN
10793    trace
10794    (p_msg      => '# rows extracted from header extract objects = '||TO_CHAR(header_cur%ROWCOUNT)
10795    ,p_level    => C_LEVEL_EVENT
10796    ,p_module   => l_log_module);
10797 END IF;
10798 --
10799 EXIT WHEN l_array_entity_id.COUNT = 0;
10800 
10801 -- initialize arrays
10802 XLA_AE_HEADER_PKG.g_rec_header_new        := NULL;
10803 XLA_AE_LINES_PKG.g_rec_lines              := NULL;
10804 
10805 --
10806 -- Bug 4458708
10807 --
10808 XLA_AE_LINES_PKG.g_LineNumber := 0;
10809 
10810 
10811 -- 4262811 - when creating Accrual Reversal or MPA, use g_last_hdr_idx to increment for next header id
10812 g_last_hdr_idx := l_array_event_id.LAST;
10813 --
10814 -- loop for the headers. Each iteration is for each header extract row
10815 -- fetched in header cursor
10816 --
10817 FOR hdr_idx IN l_array_event_id.FIRST .. l_array_event_id.LAST LOOP
10818 
10819 --
10820 -- set event info as cache for other routines to refer event attributes
10821 --
10822 XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
10823    (p_application_id           => p_application_id
10824    ,p_primary_ledger_id        => p_primary_ledger_id
10825    ,p_base_ledger_id           => p_base_ledger_id
10826    ,p_target_ledger_id         => p_target_ledger_id
10827    ,p_entity_id                => l_array_entity_id(hdr_idx)
10828    ,p_legal_entity_id          => l_array_legal_entity_id(hdr_idx)
10829    ,p_entity_code              => l_array_entity_code(hdr_idx)
10830    ,p_transaction_num          => l_array_transaction_num(hdr_idx)
10831    ,p_event_id                 => l_array_event_id(hdr_idx)
10832    ,p_event_class_code         => l_array_class_code(hdr_idx)
10833    ,p_event_type_code          => l_array_event_type(hdr_idx)
10834    ,p_event_number             => l_array_event_number(hdr_idx)
10835    ,p_event_date               => l_array_event_date(hdr_idx)
10836    ,p_transaction_date         => l_array_transaction_date(hdr_idx)
10837    ,p_reference_num_1          => l_array_reference_num_1(hdr_idx)
10838    ,p_reference_num_2          => l_array_reference_num_2(hdr_idx)
10839    ,p_reference_num_3          => l_array_reference_num_3(hdr_idx)
10840    ,p_reference_num_4          => l_array_reference_num_4(hdr_idx)
10841    ,p_reference_char_1         => l_array_reference_char_1(hdr_idx)
10842    ,p_reference_char_2         => l_array_reference_char_2(hdr_idx)
10843    ,p_reference_char_3         => l_array_reference_char_3(hdr_idx)
10844    ,p_reference_char_4         => l_array_reference_char_4(hdr_idx)
10845    ,p_reference_date_1         => l_array_reference_date_1(hdr_idx)
10846    ,p_reference_date_2         => l_array_reference_date_2(hdr_idx)
10847    ,p_reference_date_3         => l_array_reference_date_3(hdr_idx)
10848    ,p_reference_date_4         => l_array_reference_date_4(hdr_idx)
10849    ,p_event_created_by         => l_array_event_created_by(hdr_idx)
10850    ,p_budgetary_control_flag   => l_array_budgetary_control_flag(hdr_idx));
10851 
10852 --
10853 -- set the status of entry to C_VALID (0)
10854 --
10855 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status    := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
10856 
10857 --
10858 -- initialize a row for ae header
10859 --
10860 XLA_AE_HEADER_PKG.InitHeader(hdr_idx);
10861 
10862 l_event_id := l_array_event_id(hdr_idx);
10863 
10864 --
10865 -- storing the hdr_idx for event. May be used by line cursor.
10866 --
10867 g_array_event(l_event_id).array_value_num('header_index') := hdr_idx;
10868 
10869 --
10870 -- store sources from header extract. This can be improved to
10871 -- store only those sources from header extract that may be used in lines
10872 --
10873 
10874 g_array_event(l_event_id).array_value_char('source_2') := l_array_source_2(hdr_idx);
10875 g_array_event(l_event_id).array_value_char('source_3') := l_array_source_3(hdr_idx);
10876 g_array_event(l_event_id).array_value_char('source_4') := l_array_source_4(hdr_idx);
10877 g_array_event(l_event_id).array_value_char('source_9') := l_array_source_9(hdr_idx);
10878 g_array_event(l_event_id).array_value_date('source_18') := l_array_source_18(hdr_idx);
10879 
10880 --
10881 -- initilaize the status of ae headers for diffrent balance types
10882 -- the status is initialised to C_NOT_CREATED (2)
10883 --
10884 --g_array_event(l_event_id).array_value_num('actual_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
10885 --g_array_event(l_event_id).array_value_num('budget_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
10886 --g_array_event(l_event_id).array_value_num('encumbrance_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
10887 
10888 --
10889 -- call api to validate and store accounting attributes for header
10890 --
10891 
10892 ------------------------------------------------------------
10893 -- Accrual Reversal : to get date for Standard Source (NONE)
10894 ------------------------------------------------------------
10895 l_acc_rev_gl_date_source := NULL;
10896 
10897      l_rec_acct_attrs.array_acct_attr_code(1)   := 'GL_DATE';
10898       l_rec_acct_attrs.array_date_value(1) := g_array_event(l_event_id).array_value_date('source_18');
10899 
10900 
10904 
10901 XLA_AE_HEADER_PKG.SetHdrAcctAttrs(l_rec_acct_attrs);
10902 
10903 XLA_AE_HEADER_PKG.SetJeCategoryName;
10905 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_type_code(hdr_idx)  := l_array_event_type(hdr_idx);
10906 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_id(hdr_idx)         := l_array_event_id(hdr_idx);
10907 XLA_AE_HEADER_PKG.g_rec_header_new.array_entity_id(hdr_idx)        := l_array_entity_id(hdr_idx);
10908 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_number(hdr_idx)     := l_array_event_number(hdr_idx);
10909 XLA_AE_HEADER_PKG.g_rec_header_new.array_target_ledger_id(hdr_idx) := p_target_ledger_id;
10910 
10911 
10912 --
10913 xla_ae_header_pkg.SetHdrDescription(
10914    p_description => Description_2 (
10915    p_application_id => p_application_id 
10916  , p_source_2 => g_array_event(l_event_id).array_value_char('source_2')
10917  , p_source_3 => g_array_event(l_event_id).array_value_char('source_3')
10918  , p_source_4 => g_array_event(l_event_id).array_value_char('source_4')
10919    )
10920 );
10921 --
10922 
10923 -- No header level analytical criteria
10924 
10925 --
10926 --accounting attribute enhancement, bug 3612931
10927 --
10928 l_trx_reversal_source := SUBSTR(NULL, 1,30);
10929 
10930 IF NVL(l_trx_reversal_source, 'N') NOT IN ('N','Y') THEN
10931    xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
10932 
10933    xla_accounting_err_pkg.build_message
10934       (p_appli_s_name            => 'XLA'
10935       ,p_msg_name                => 'XLA_AP_INVALID_HDR_ATTR'
10936       ,p_token_1                 => 'ACCT_ATTR_NAME'
10937       ,p_value_1                 => xla_ae_sources_pkg.GetAccountingSourceName('TRX_ACCT_REVERSAL_OPTION')
10938       ,p_token_2                 => 'PRODUCT_NAME'
10939       ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
10940       ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
10941       ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
10942       ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
10943 
10944 ELSIF NVL(l_trx_reversal_source, 'N') = 'Y' THEN
10945    --
10946    -- following sets the accounting attributes needed to reverse
10947    -- accounting for a distributeion
10948    --
10949    xla_ae_lines_pkg.SetTrxReversalAttrs
10950       (p_event_id              => l_event_id
10951       ,p_gl_date               => XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(hdr_idx)
10952       ,p_trx_reversal_source   => l_trx_reversal_source);
10953 
10954 END IF;
10955 
10956 
10957 ----------------------------------------------------------------
10958 -- 4262811 -  update the header statuses to invalid in need be
10959 ----------------------------------------------------------------
10960 --
10961 XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus (p_hdr_idx => hdr_idx);
10962 
10963 
10964   -----------------------------------------------
10965   -- No accrual reversal for the event class/type
10966   -----------------------------------------------
10967 ----------------------------------------------------------------
10968 
10969 --
10970 -- this ends the header loop iteration for one bulk fetch
10971 --
10972 END LOOP;
10973 
10974 l_first_event_id   := l_array_event_id(l_array_event_id.FIRST);
10975 l_last_event_id    := l_array_event_id(l_array_event_id.LAST);
10976 
10977 --
10978 -- insert dummy rows into lines gt table that were created due to
10979 -- transaction reversals
10980 --
10981 IF XLA_AE_LINES_PKG.g_rec_lines.array_ae_header_id.COUNT > 0 THEN
10982    l_result := XLA_AE_LINES_PKG.InsertLines;
10983 END IF;
10984 
10985 --
10986 -- reset the temp_line_num for each set of events fetched from header
10987 -- cursor rather than doing it for each new event in line cursor
10988 -- Bug 3939231
10989 --
10990 xla_ae_lines_pkg.g_temp_line_num := 0;
10991 
10992 
10993 
10994 --
10995 OPEN line_cur(x_first_event_id  => l_first_event_id, x_last_event_id  => l_last_event_id);
10996 --
10997 --
10998 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
10999 
11000       trace
11001          (p_msg      => 'SQL - FETCH line_cur'
11002          ,p_level    => C_LEVEL_STATEMENT
11003          ,p_module   => l_log_module);
11004 
11005 END IF;
11006 --
11007 --
11008 LOOP
11009   --
11010   FETCH line_cur BULK COLLECT INTO
11011         l_array_entity_id
11012       , l_array_legal_entity_id
11013       , l_array_entity_code
11014       , l_array_transaction_num
11015       , l_array_event_id
11016       , l_array_class_code
11017       , l_array_event_type
11018       , l_array_event_number
11019       , l_array_event_date
11020       , l_array_transaction_date
11021       , l_array_reference_num_1
11022       , l_array_reference_num_2
11023       , l_array_reference_num_3
11024       , l_array_reference_num_4
11025       , l_array_reference_char_1
11026       , l_array_reference_char_2
11027       , l_array_reference_char_3
11028       , l_array_reference_char_4
11029       , l_array_reference_date_1
11030       , l_array_reference_date_2
11031       , l_array_reference_date_3
11032       , l_array_reference_date_4
11033       , l_array_event_created_by
11034       , l_array_budgetary_control_flag
11035       , l_array_extract_line_num 
11036       , l_array_source_1
11037       , l_array_source_5
11038       , l_array_source_6
11042       , l_array_source_12
11039       , l_array_source_8
11040       , l_array_source_10
11041       , l_array_source_11
11043       LIMIT l_rows;
11044 
11045   --
11046   IF (C_LEVEL_EVENT >= g_log_level) THEN
11047             trace
11048                (p_msg      => '# rows extracted from line extract objects = '||TO_CHAR(line_cur%ROWCOUNT)
11049                ,p_level    => C_LEVEL_EVENT
11050                ,p_module   => l_log_module);
11051   END IF;
11052   --
11053   EXIT WHEN l_array_entity_id.count = 0;
11054 
11055   XLA_AE_LINES_PKG.g_rec_lines := null;
11056 
11057 --
11058 -- Bug 4458708
11059 --
11060 XLA_AE_LINES_PKG.g_LineNumber := 0;
11061 --
11062 --
11063 
11064 FOR Idx IN 1..l_array_event_id.count LOOP
11065    --
11066    -- 5648433 (move l_event_id out of IF statement)  set l_event_id to be used inside IF condition
11067    --
11068    l_event_id := l_array_event_id(idx);  -- 5648433
11069 
11070    --
11071    -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
11072    --
11073 
11074    IF NVL(xla_ae_header_pkg.g_rec_header_new.array_trx_acct_reversal_option
11075              (g_array_event(l_event_id).array_value_num('header_index'))
11076          ,'N'
11077          ) <> 'Y'
11078    THEN
11079       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
11080          trace
11081             (p_msg      => 'Trancaction revesal option is not Y '
11082             ,p_level    => C_LEVEL_STATEMENT
11083             ,p_module   => l_log_module);
11084       END IF;
11085 
11086 --
11087 -- set the XLA_AE_JOURNAL_ENTRY_PKG.g_global_status to C_VALID (0)
11088 --
11089 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
11090 --
11091 -- set event info as cache for other routines to refer event attributes
11092 --
11093 
11094 IF l_event_id <> NVL(l_previous_event_id, -1) THEN
11095    l_previous_event_id := l_event_id;
11096 
11097    XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
11098       (p_application_id           => p_application_id
11099       ,p_primary_ledger_id        => p_primary_ledger_id
11100       ,p_base_ledger_id           => p_base_ledger_id
11101       ,p_target_ledger_id         => p_target_ledger_id
11102       ,p_entity_id                => l_array_entity_id(Idx)
11103       ,p_legal_entity_id          => l_array_legal_entity_id(Idx)
11104       ,p_entity_code              => l_array_entity_code(Idx)
11105       ,p_transaction_num          => l_array_transaction_num(Idx)
11106       ,p_event_id                 => l_array_event_id(Idx)
11107       ,p_event_class_code         => l_array_class_code(Idx)
11108       ,p_event_type_code          => l_array_event_type(Idx)
11109       ,p_event_number             => l_array_event_number(Idx)
11110       ,p_event_date               => l_array_event_date(Idx)
11111       ,p_transaction_date         => l_array_transaction_date(Idx)
11112       ,p_reference_num_1          => l_array_reference_num_1(Idx)
11113       ,p_reference_num_2          => l_array_reference_num_2(Idx)
11114       ,p_reference_num_3          => l_array_reference_num_3(Idx)
11115       ,p_reference_num_4          => l_array_reference_num_4(Idx)
11116       ,p_reference_char_1         => l_array_reference_char_1(Idx)
11117       ,p_reference_char_2         => l_array_reference_char_2(Idx)
11118       ,p_reference_char_3         => l_array_reference_char_3(Idx)
11119       ,p_reference_char_4         => l_array_reference_char_4(Idx)
11120       ,p_reference_date_1         => l_array_reference_date_1(Idx)
11121       ,p_reference_date_2         => l_array_reference_date_2(Idx)
11122       ,p_reference_date_3         => l_array_reference_date_3(Idx)
11123       ,p_reference_date_4         => l_array_reference_date_4(Idx)
11124       ,p_event_created_by         => l_array_event_created_by(Idx)
11125       ,p_budgetary_control_flag   => l_array_budgetary_control_flag(Idx));
11126        --
11127 END IF;
11128 
11129 
11130 
11131 --
11132 xla_ae_lines_pkg.SetExtractLine(p_extract_line => l_array_extract_line_num(Idx));
11133 
11134 l_acct_reversal_source := SUBSTR(NULL, 1,30);
11135 
11136 IF l_continue_with_lines THEN
11137    IF NVL(l_acct_reversal_source, 'N') NOT IN ('N','Y','B') THEN
11138       xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
11139 
11140       xla_accounting_err_pkg.build_message
11141          (p_appli_s_name            => 'XLA'
11142          ,p_msg_name                => 'XLA_AP_INVALID_REVERSAL_OPTION'
11143          ,p_token_1                 => 'LINE_NUMBER'
11144          ,p_value_1                 => l_array_extract_line_num(Idx)
11145          ,p_token_2                 => 'PRODUCT_NAME'
11146          ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
11147          ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
11148          ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
11149          ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
11150 
11151    ELSIF NVL(l_acct_reversal_source, 'N') IN ('Y','B') THEN
11152       --
11153       -- following sets the accounting attributes needed to reverse
11154       -- accounting for a distributeion
11155       --
11156 
11157       --
11158       -- 5217187
11159       --
11160       l_rec_rev_acct_attrs.array_acct_attr_code(1):= 'GL_DATE';
11164       --
11161       l_rec_rev_acct_attrs.array_date_value(1) := XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(
11162                                        g_array_event(l_event_id).array_value_num('header_index'));
11163       --
11165 
11166       -- No reversal code generated
11167 
11168       xla_ae_lines_pkg.SetAcctReversalAttrs
11169          (p_event_id             => l_event_id
11170          ,p_rec_acct_attrs       => l_rec_rev_acct_attrs
11171          ,p_calculate_acctd_flag => l_calculate_acctd_flag
11172          ,p_calculate_g_l_flag   => l_calculate_g_l_flag);
11173    END IF;
11174 
11175    IF NVL(l_acct_reversal_source, 'N') IN ('N','B') THEN
11176        l_actual_flag := NULL;  l_actual_gain_loss_ref := '#####';
11177 
11178 --
11179 AcctLineType_12 (
11180  p_application_id  => p_application_id
11181  ,p_event_id     => l_event_id
11182  ,p_calculate_acctd_flag => l_calculate_acctd_flag
11183  ,p_calculate_g_l_flag => l_calculate_g_l_flag
11184  ,p_actual_flag => l_actual_flag
11185  ,p_balance_type_code => l_balance_type_code
11186  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
11187  
11188  , p_source_1 => l_array_source_1(Idx)
11189  , p_source_5 => l_array_source_5(Idx)
11190  , p_source_6 => l_array_source_6(Idx)
11191  , p_source_8 => l_array_source_8(Idx)
11192  , p_source_9 => g_array_event(l_event_id).array_value_char('source_9')
11193  , p_source_10 => l_array_source_10(Idx)
11194  , p_source_11 => l_array_source_11(Idx)
11195  );
11196 If(l_balance_type_code = 'A') THEN
11197   l_actual_gain_loss_ref := l_gain_or_loss_ref;
11198 END IF;
11199 
11200 --
11201 
11202 
11203 --
11204 AcctLineType_13 (
11205  p_application_id  => p_application_id
11206  ,p_event_id     => l_event_id
11207  ,p_calculate_acctd_flag => l_calculate_acctd_flag
11208  ,p_calculate_g_l_flag => l_calculate_g_l_flag
11209  ,p_actual_flag => l_actual_flag
11210  ,p_balance_type_code => l_balance_type_code
11211  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
11212  
11213  , p_source_1 => l_array_source_1(Idx)
11214  , p_source_5 => l_array_source_5(Idx)
11215  , p_source_8 => l_array_source_8(Idx)
11216  , p_source_9 => g_array_event(l_event_id).array_value_char('source_9')
11217  , p_source_10 => l_array_source_10(Idx)
11218  , p_source_11 => l_array_source_11(Idx)
11219  , p_source_12 => l_array_source_12(Idx)
11220  );
11221 If(l_balance_type_code = 'A') THEN
11222   l_actual_gain_loss_ref := l_gain_or_loss_ref;
11223 END IF;
11224 
11225 --
11226 
11227       -- only execute it if calculate g/l flag is yes, and primary or secondary ledger
11228       -- or secondary ledger that has different currency with primary
11229       -- or alc that is calculated by sla
11230       IF (((l_calculate_g_l_flag = 'Y' AND XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_category_code <> 'ALC') or
11231             (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_category_code in ('ALC', 'SECONDARY') AND XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.calculate_amts_flag='Y'))
11232 
11233 --      IF((l_calculate_g_l_flag='Y' or XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id <>
11234 --                    XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id)
11235           AND (l_actual_flag = 'A')) THEN
11236         XLA_AE_LINES_PKG.CreateGainOrLossLines(
11237           p_event_id         => xla_ae_journal_entry_pkg.g_cache_event.event_id
11238          ,p_application_id   => p_application_id
11239          ,p_amb_context_code => 'DEFAULT'
11240          ,p_entity_code      => xla_ae_journal_entry_pkg.g_cache_event.entity_code
11241          ,p_event_class_code => C_EVENT_CLASS_CODE
11242          ,p_event_type_code  => C_EVENT_TYPE_CODE
11243          
11244          ,p_gain_ccid        => -1
11245          ,p_loss_ccid        => -1
11246 
11247          ,p_actual_flag      => l_actual_flag
11248          ,p_enc_flag         => null
11249          ,p_actual_g_l_ref   => l_actual_gain_loss_ref
11250          ,p_enc_g_l_ref      => null
11251          );
11252       END IF;
11253    END IF;
11254 END IF;
11255 
11256    ELSE
11257       --
11258       -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
11259       --
11260       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
11261          trace
11262             (p_msg      => 'Trancaction revesal option is Y'
11263             ,p_level    => C_LEVEL_STATEMENT
11264             ,p_module   => l_log_module);
11265       END IF;
11266    END IF;
11267 
11268 END LOOP;
11269 l_result := XLA_AE_LINES_PKG.InsertLines ;
11270 end loop;
11271 close line_cur;
11272 
11273 
11274 --
11275 -- insert headers into xla_ae_headers_gt table
11276 --
11277 l_result := XLA_AE_HEADER_PKG.InsertHeaders ;
11278 
11279 -- insert into errors table here.
11280 
11281 END LOOP;
11282 
11283 --
11284 -- 4865292
11285 --
11286 -- Compare g_hdr_extract_count with event count in
11287 -- CreateHeadersAndLines.
11288 --
11289 g_hdr_extract_count := g_hdr_extract_count + header_cur%ROWCOUNT;
11290 
11291 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
11292    trace (p_msg     => '# rows extracted from header extract objects '
11293                     || ' (running total): '
11294                     || g_hdr_extract_count
11295          ,p_level   => C_LEVEL_STATEMENT
11296          ,p_module  => l_log_module);
11300 --
11297 END IF;
11298 
11299 CLOSE header_cur;
11301 
11302 --
11303 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
11304    trace
11305       (p_msg      => 'END of EventClass_20'
11306       ,p_level    => C_LEVEL_PROCEDURE
11307       ,p_module   => l_log_module);
11308 END IF;
11309 --
11310 RETURN l_result;
11311 EXCEPTION
11312 WHEN xla_exceptions_pkg.application_exception THEN
11313    
11314 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
11315 
11316    
11317 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
11318 
11319    RAISE;
11320 WHEN OTHERS THEN
11321    xla_exceptions_pkg.raise_message
11322       (p_location => 'XLA_08407_AAD_S_000013_BC_PKG.EventClass_20');
11323 END EventClass_20;
11324 --
11325 
11326 ---------------------------------------
11327 --
11328 -- PRIVATE PROCEDURE
11329 --         insert_sources_21
11330 --
11331 ----------------------------------------
11332 --
11333 PROCEDURE insert_sources_21(
11334                                 p_target_ledger_id       IN NUMBER
11335                               , p_language               IN VARCHAR2
11336                               , p_sla_ledger_id          IN NUMBER
11337                               , p_pad_start_date         IN DATE
11338                               , p_pad_end_date           IN DATE
11339                          )
11340 IS
11341 
11342 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'CC_PURCHASE_ORDERS_ALL';
11343 C_EVENT_CLASS_CODE   CONSTANT  VARCHAR2(30) := 'CC_PURCHASE_ORDERS';
11344 p_apps_owner                   VARCHAR2(30);
11345 l_log_module                   VARCHAR2(240);
11346 BEGIN
11347 IF g_log_enabled THEN
11348       l_log_module := C_DEFAULT_MODULE||'.insert_sources_21';
11349 END IF;
11350 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
11351 
11352       trace
11353          (p_msg      => 'BEGIN of insert_sources_21'
11354          ,p_level    => C_LEVEL_PROCEDURE
11355          ,p_module   => l_log_module);
11356 
11357 END IF;
11358 
11359 -- select APPS owner
11360 SELECT oracle_username
11361   INTO p_apps_owner
11362   FROM fnd_oracle_userid
11363  WHERE read_only_flag = 'U'
11364 ;
11365 
11366 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
11367       trace
11368          (p_msg      => 'p_target_ledger_id = '||p_target_ledger_id||
11369                         ' - p_language = '||p_language||
11370                         ' - p_sla_ledger_id  = '||p_sla_ledger_id ||
11371                         ' - p_pad_start_date = '||TO_CHAR(p_pad_start_date)||
11372                         ' - p_pad_end_date = '||TO_CHAR(p_pad_end_date)||
11373                         ' - p_apps_owner = '||TO_CHAR(p_apps_owner)
11374          ,p_level    => C_LEVEL_STATEMENT
11375          ,p_module   => l_log_module);
11376 END IF;
11377 
11378 
11379 --
11380 INSERT INTO xla_diag_sources --hdr2
11381 (
11382         event_id
11383       , ledger_id
11384       , sla_ledger_id
11385       , description_language
11386       , object_name
11387       , object_type_code
11388       , line_number
11389       , source_application_id
11390       , source_type_code
11391       , source_code
11392       , source_value
11393       , source_meaning
11394       , created_by
11395       , creation_date
11396       , last_update_date
11397       , last_updated_by
11398       , last_update_login
11399       , program_update_date
11400       , program_application_id
11401       , program_id
11402       , request_id
11403 )
11404 SELECT
11405         event_id
11406       , p_target_ledger_id
11407       , p_sla_ledger_id
11408       , p_language
11409       , object_name
11410       , object_type_code
11411       , line_number
11412       , source_application_id
11413       , source_type_code
11414       , source_code
11415       , SUBSTR(source_value ,1,1996)
11416       , SUBSTR(source_meaning ,1,200)
11417       , xla_environment_pkg.g_Usr_Id
11418       , TRUNC(SYSDATE)
11419       , TRUNC(SYSDATE)
11420       , xla_environment_pkg.g_Usr_Id
11421       , xla_environment_pkg.g_Login_Id
11422       , TRUNC(SYSDATE)
11423       , xla_environment_pkg.g_Prog_Appl_Id
11424       , xla_environment_pkg.g_Prog_Id
11425       , xla_environment_pkg.g_Req_Id
11426   FROM (
11427        SELECT xet.event_id                  event_id
11428             , 0                          line_number
11429             , CASE r
11430                WHEN 1 THEN 'IGC_CC_EVENT_JE_HEADER_V' 
11431                 WHEN 2 THEN 'IGC_CC_EVENT_JE_HEADER_V' 
11432                 WHEN 3 THEN 'IGC_CC_EVENT_JE_HEADER_V' 
11433                 WHEN 4 THEN 'IGC_CC_EVENT_JE_HEADER_V' 
11434                 WHEN 5 THEN 'IGC_CC_EVENT_JE_HEADER_V' 
11435                 
11436                ELSE null
11437               END                           object_name
11438             , CASE r
11439                 WHEN 1 THEN 'HEADER' 
11440                 WHEN 2 THEN 'HEADER' 
11441                 WHEN 3 THEN 'HEADER' 
11442                 WHEN 4 THEN 'HEADER' 
11443                 WHEN 5 THEN 'HEADER' 
11444                 
11445                 ELSE null
11446               END                           object_type_code
11447             , CASE r
11451                 WHEN 4 THEN '8407' 
11448                 WHEN 1 THEN '8407' 
11449                 WHEN 2 THEN '8407' 
11450                 WHEN 3 THEN '8407' 
11452                 WHEN 5 THEN '8407' 
11453                 
11454                 ELSE null
11455               END                           source_application_id
11456             , 'S'             source_type_code
11457             , CASE r
11458                 WHEN 1 THEN 'HEADER_DESC' 
11459                 WHEN 2 THEN 'REFERENCE_4' 
11460                 WHEN 3 THEN 'REFERENCE_3' 
11461                 WHEN 4 THEN 'DOCUMENT_TYPE' 
11462                 WHEN 5 THEN 'ACCOUNTING_DATE' 
11463                 
11464                 ELSE null
11465               END                           source_code
11466             , CASE r
11467                 WHEN 1 THEN TO_CHAR(h1.HEADER_DESC)
11468                 WHEN 2 THEN TO_CHAR(h1.REFERENCE_4)
11469                 WHEN 3 THEN TO_CHAR(h1.REFERENCE_3)
11470                 WHEN 4 THEN TO_CHAR(h1.DOCUMENT_TYPE)
11471                 WHEN 5 THEN TO_CHAR(h1.ACCOUNTING_DATE)
11472                 
11473                 ELSE null
11474               END                           source_value
11475             , null              source_meaning
11476          FROM xla_events_gt     xet  
11477       , IGC_CC_EVENT_JE_HEADER_V  h1
11478              ,(select rownum r from all_objects where rownum <= 5 and owner = p_apps_owner)
11479          WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
11480            AND xet.event_class_code = C_EVENT_CLASS_CODE
11481               AND h1.event_id = xet.event_id
11482 
11483 )
11484 ;
11485 --
11486 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
11487 
11488       trace
11489          (p_msg      => 'number of header sources inserted = '||SQL%ROWCOUNT
11490          ,p_level    => C_LEVEL_STATEMENT
11491          ,p_module   => l_log_module);
11492 
11493 END IF;
11494 --
11495 
11496 
11497 
11498 --
11499 INSERT INTO xla_diag_sources  --line2
11500 (
11501         event_id
11502       , ledger_id
11503       , sla_ledger_id
11504       , description_language
11505       , object_name
11506       , object_type_code
11507       , line_number
11508       , source_application_id
11509       , source_type_code
11510       , source_code
11511       , source_value
11512       , source_meaning
11513       , created_by
11514       , creation_date
11515       , last_update_date
11516       , last_updated_by
11517       , last_update_login
11518       , program_update_date
11519       , program_application_id
11520       , program_id
11521       , request_id
11522 )
11523 SELECT  event_id
11524       , p_target_ledger_id
11525       , p_sla_ledger_id
11526       , p_language
11527       , object_name
11528       , object_type_code
11529       , line_number
11530       , source_application_id
11531       , source_type_code
11532       , source_code
11533       , SUBSTR(source_value,1,1996)
11534       , SUBSTR(source_meaning ,1,200)
11535       , xla_environment_pkg.g_Usr_Id
11536       , TRUNC(SYSDATE)
11537       , TRUNC(SYSDATE)
11538       , xla_environment_pkg.g_Usr_Id
11539       , xla_environment_pkg.g_Login_Id
11540       , TRUNC(SYSDATE)
11541       , xla_environment_pkg.g_Prog_Appl_Id
11542       , xla_environment_pkg.g_Prog_Id
11543       , xla_environment_pkg.g_Req_Id
11544   FROM (
11545        SELECT xet.event_id                  event_id
11546             , l2.line_number                 line_number
11547             , CASE r
11548                WHEN 1 THEN 'IGC_CC_EVENT_JE_LINES_V' 
11549                 WHEN 2 THEN 'IGC_CC_EVENT_JE_LINES_V' 
11550                 WHEN 3 THEN 'IGC_CC_EVENT_JE_LINES_V' 
11551                 WHEN 4 THEN 'IGC_CC_EVENT_JE_LINES_V' 
11552                 WHEN 5 THEN 'IGC_CC_EVENT_JE_LINES_V' 
11553                 WHEN 6 THEN 'IGC_CC_EVENT_JE_LINES_V' 
11554                 WHEN 7 THEN 'IGC_CC_EVENT_JE_LINES_V' 
11555                 
11556                ELSE null
11557               END                           object_name
11558             , CASE r
11559                 WHEN 1 THEN 'LINE' 
11560                 WHEN 2 THEN 'LINE' 
11561                 WHEN 3 THEN 'LINE' 
11562                 WHEN 4 THEN 'LINE' 
11563                 WHEN 5 THEN 'LINE' 
11564                 WHEN 6 THEN 'LINE' 
11565                 WHEN 7 THEN 'LINE' 
11566                 
11567                 ELSE null
11568               END                           object_type_code
11569             , CASE r
11570                 WHEN 1 THEN '8407' 
11571                 WHEN 2 THEN '8407' 
11572                 WHEN 3 THEN '8407' 
11573                 WHEN 4 THEN '8407' 
11574                 WHEN 5 THEN '8407' 
11575                 WHEN 6 THEN '8407' 
11576                 WHEN 7 THEN '8407' 
11577                 
11578                 ELSE null
11579               END                           source_application_id
11580             , 'S'             source_type_code
11581             , CASE r
11582                 WHEN 1 THEN 'TRANSACTION_DESCRIPTION' 
11583                 WHEN 2 THEN 'CODE_COMBINATION_ID' 
11584                 WHEN 3 THEN 'CC_FUNC_CR_AMT' 
11585                 WHEN 4 THEN 'CC_ACCT_LINE_ID' 
11586                 WHEN 5 THEN 'CC_FUNC_AMT' 
11587                 WHEN 6 THEN 'CURRENCY_CODE' 
11588                 WHEN 7 THEN 'CC_FUNC_DR_AMT' 
11592             , CASE r
11589                 
11590                 ELSE null
11591               END                           source_code
11593                 WHEN 1 THEN TO_CHAR(l2.TRANSACTION_DESCRIPTION)
11594                 WHEN 2 THEN TO_CHAR(l2.CODE_COMBINATION_ID)
11595                 WHEN 3 THEN TO_CHAR(l2.CC_FUNC_CR_AMT)
11596                 WHEN 4 THEN TO_CHAR(l2.CC_ACCT_LINE_ID)
11597                 WHEN 5 THEN TO_CHAR(l2.CC_FUNC_AMT)
11598                 WHEN 6 THEN TO_CHAR(l2.CURRENCY_CODE)
11599                 WHEN 7 THEN TO_CHAR(l2.CC_FUNC_DR_AMT)
11600                 
11601                 ELSE null
11602               END                           source_value
11603             , null              source_meaning
11604          FROM  xla_events_gt     xet  
11605         , IGC_CC_EVENT_JE_LINES_V  l2
11606             , (select rownum r from all_objects where rownum <= 7 and owner = p_apps_owner)
11607         WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
11608           AND xet.event_class_code = C_EVENT_CLASS_CODE
11609             AND l2.event_id          = xet.event_id
11610 
11611 )
11612 ;
11613 --
11614 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
11615 
11616       trace
11617          (p_msg      => 'number of line sources inserted = '||SQL%ROWCOUNT
11618          ,p_level    => C_LEVEL_STATEMENT
11619          ,p_module   => l_log_module);
11620 
11621 END IF;
11622 
11623 
11624 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
11625       trace
11626          (p_msg      => 'END of insert_sources_21'
11627          ,p_level    => C_LEVEL_PROCEDURE
11628          ,p_module   => l_log_module);
11629 END IF;
11630 EXCEPTION
11631   WHEN xla_exceptions_pkg.application_exception THEN
11632       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
11633             trace
11634                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
11635                ,p_level    => C_LEVEL_EXCEPTION
11636                ,p_module   => l_log_module);
11637       END IF;
11638       RAISE;
11639   WHEN OTHERS THEN
11640       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
11641             trace
11642                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
11643                ,p_level    => C_LEVEL_EXCEPTION
11644                ,p_module   => l_log_module);
11645        END IF;
11646        xla_exceptions_pkg.raise_message
11647            (p_location => 'XLA_08407_AAD_S_000013_BC_PKG.insert_sources_21');
11648 END insert_sources_21;
11649 --
11650 
11651 ---------------------------------------
11652 --
11653 -- PRIVATE FUNCTION
11654 --         EventClass_21
11655 --
11656 ----------------------------------------
11657 --
11658 FUNCTION EventClass_21
11659        (p_application_id         IN NUMBER
11660        ,p_base_ledger_id         IN NUMBER
11661        ,p_target_ledger_id       IN NUMBER
11662        ,p_language               IN VARCHAR2
11663        ,p_currency_code          IN VARCHAR2
11664        ,p_sla_ledger_id          IN NUMBER
11665        ,p_pad_start_date         IN DATE
11666        ,p_pad_end_date           IN DATE
11667        ,p_primary_ledger_id      IN NUMBER)
11668 RETURN BOOLEAN IS
11669 --
11670 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'CC_PURCHASE_ORDERS_ALL';
11671 C_EVENT_CLASS_CODE    CONSTANT  VARCHAR2(30) := 'CC_PURCHASE_ORDERS';
11672 
11673 l_calculate_acctd_flag   VARCHAR2(1) :='N';
11674 l_calculate_g_l_flag     VARCHAR2(1) :='N';
11675 --
11676 l_array_legal_entity_id                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
11677 l_array_entity_id                      XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
11678 l_array_entity_code                    XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
11679 l_array_transaction_num                XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
11680 l_array_event_id                       XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
11681 l_array_class_code                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
11682 l_array_event_type                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
11683 l_array_event_number                   XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
11684 l_array_event_date                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
11685 l_array_transaction_date               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
11686 l_array_reference_num_1                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
11687 l_array_reference_num_2                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
11688 l_array_reference_num_3                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
11689 l_array_reference_num_4                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
11690 l_array_reference_char_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
11691 l_array_reference_char_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
11692 l_array_reference_char_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
11693 l_array_reference_char_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
11694 l_array_reference_date_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
11695 l_array_reference_date_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
11696 l_array_reference_date_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
11697 l_array_reference_date_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
11698 l_array_event_created_by               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V100L;
11699 l_array_budgetary_control_flag         XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
11700 
11701 l_event_id                             NUMBER;
11702 l_previous_event_id                    NUMBER;
11706 l_rec_acct_attrs                       XLA_AE_HEADER_PKG.t_rec_acct_attrs;
11703 l_first_event_id                       NUMBER;
11704 l_last_event_id                        NUMBER;
11705 
11707 l_rec_rev_acct_attrs                   XLA_AE_LINES_PKG.t_rec_acct_attrs;
11708 --
11709 --
11710 l_result                    BOOLEAN := TRUE;
11711 l_rows                      NUMBER  := 1000;
11712 l_event_type_name           VARCHAR2(80) := 'All';
11713 l_event_class_name          VARCHAR2(80) := 'CC Purchase Orders';
11714 l_description               VARCHAR2(4000);
11715 l_transaction_reversal      NUMBER;
11716 l_ae_header_id              NUMBER;
11717 l_array_extract_line_num    xla_ae_journal_entry_pkg.t_array_Num;
11718 l_log_module                VARCHAR2(240);
11719 --
11720 l_acct_reversal_source      VARCHAR2(30);
11721 l_trx_reversal_source       VARCHAR2(30);
11722 
11723 l_continue_with_lines       BOOLEAN := TRUE;
11724 --
11725 l_acc_rev_gl_date_source    DATE;                      -- 4262811
11726 --
11727 type t_array_event_id is table of number index by binary_integer;
11728 
11729 l_rec_array_event                    t_rec_array_event;
11730 l_null_rec_array_event               t_rec_array_event;
11731 l_array_ae_header_id                 xla_number_array_type;
11732 l_actual_flag                        VARCHAR2(1) := NULL;
11733 l_actual_gain_loss_ref               VARCHAR2(30) := '#####';
11734 l_balance_type_code                  VARCHAR2(1) :=NULL;
11735 l_gain_or_loss_ref                   VARCHAR2(30) :=NULL;
11736 
11737 --
11738 TYPE t_array_lookup_meaning IS TABLE OF fnd_lookup_values.meaning%TYPE INDEX BY BINARY_INTEGER;
11739 --
11740 
11741 TYPE t_array_source_2 IS TABLE OF IGC_CC_EVENT_JE_HEADER_V.HEADER_DESC%TYPE INDEX BY BINARY_INTEGER;
11742 TYPE t_array_source_3 IS TABLE OF IGC_CC_EVENT_JE_HEADER_V.REFERENCE_4%TYPE INDEX BY BINARY_INTEGER;
11743 TYPE t_array_source_4 IS TABLE OF IGC_CC_EVENT_JE_HEADER_V.REFERENCE_3%TYPE INDEX BY BINARY_INTEGER;
11744 TYPE t_array_source_9 IS TABLE OF IGC_CC_EVENT_JE_HEADER_V.DOCUMENT_TYPE%TYPE INDEX BY BINARY_INTEGER;
11745 TYPE t_array_source_18 IS TABLE OF IGC_CC_EVENT_JE_HEADER_V.ACCOUNTING_DATE%TYPE INDEX BY BINARY_INTEGER;
11746 
11747 TYPE t_array_source_1 IS TABLE OF IGC_CC_EVENT_JE_LINES_V.TRANSACTION_DESCRIPTION%TYPE INDEX BY BINARY_INTEGER;
11748 TYPE t_array_source_5 IS TABLE OF IGC_CC_EVENT_JE_LINES_V.CODE_COMBINATION_ID%TYPE INDEX BY BINARY_INTEGER;
11749 TYPE t_array_source_6 IS TABLE OF IGC_CC_EVENT_JE_LINES_V.CC_FUNC_CR_AMT%TYPE INDEX BY BINARY_INTEGER;
11750 TYPE t_array_source_8 IS TABLE OF IGC_CC_EVENT_JE_LINES_V.CC_ACCT_LINE_ID%TYPE INDEX BY BINARY_INTEGER;
11751 TYPE t_array_source_10 IS TABLE OF IGC_CC_EVENT_JE_LINES_V.CC_FUNC_AMT%TYPE INDEX BY BINARY_INTEGER;
11752 TYPE t_array_source_11 IS TABLE OF IGC_CC_EVENT_JE_LINES_V.CURRENCY_CODE%TYPE INDEX BY BINARY_INTEGER;
11753 TYPE t_array_source_12 IS TABLE OF IGC_CC_EVENT_JE_LINES_V.CC_FUNC_DR_AMT%TYPE INDEX BY BINARY_INTEGER;
11754 
11755 l_array_source_2              t_array_source_2;
11756 l_array_source_3              t_array_source_3;
11757 l_array_source_4              t_array_source_4;
11758 l_array_source_9              t_array_source_9;
11759 l_array_source_18              t_array_source_18;
11760 
11761 l_array_source_1      t_array_source_1;
11762 l_array_source_5      t_array_source_5;
11763 l_array_source_6      t_array_source_6;
11764 l_array_source_8      t_array_source_8;
11765 l_array_source_10      t_array_source_10;
11766 l_array_source_11      t_array_source_11;
11767 l_array_source_12      t_array_source_12;
11768 
11769 --
11770 CURSOR header_cur
11771 IS
11772 SELECT /*+ leading(xet) cardinality(xet,1) */
11773 -- Event Class Code: CC_PURCHASE_ORDERS
11774     xet.entity_id
11775    ,xet.legal_entity_id
11776    ,xet.entity_code
11777    ,xet.transaction_number
11778    ,xet.event_id
11779    ,xet.event_class_code
11780    ,xet.event_type_code
11781    ,xet.event_number
11782    ,xet.event_date
11783    ,xet.transaction_date
11784    ,xet.reference_num_1
11785    ,xet.reference_num_2
11786    ,xet.reference_num_3
11787    ,xet.reference_num_4
11788    ,xet.reference_char_1
11789    ,xet.reference_char_2
11790    ,xet.reference_char_3
11791    ,xet.reference_char_4
11792    ,xet.reference_date_1
11793    ,xet.reference_date_2
11794    ,xet.reference_date_3
11795    ,xet.reference_date_4
11796    ,xet.event_created_by
11797    ,xet.budgetary_control_flag 
11798   , h1.HEADER_DESC    source_2
11799   , h1.REFERENCE_4    source_3
11800   , h1.REFERENCE_3    source_4
11801   , h1.DOCUMENT_TYPE    source_9
11802   , h1.ACCOUNTING_DATE    source_18
11803   FROM xla_events_gt     xet 
11804   , IGC_CC_EVENT_JE_HEADER_V  h1
11805  WHERE xet.event_date between p_pad_start_date and p_pad_end_date
11806    and xet.event_class_code = C_EVENT_CLASS_CODE
11807    and xet.event_status_code <> 'N'  AND h1.event_id = xet.event_id
11808 
11809  ORDER BY event_id
11810 ;
11811 
11812 
11813 --
11814 CURSOR line_cur (x_first_event_id    in number, x_last_event_id    in number)
11815 IS
11816 SELECT  /*+ leading(xet) cardinality(xet,1) */
11817 -- Event Class Code: CC_PURCHASE_ORDERS
11818     xet.entity_id
11819    ,xet.legal_entity_id
11820    ,xet.entity_code
11821    ,xet.transaction_number
11822    ,xet.event_id
11823    ,xet.event_class_code
11824    ,xet.event_type_code
11825    ,xet.event_number
11826    ,xet.event_date
11830    ,xet.reference_num_3
11827    ,xet.transaction_date
11828    ,xet.reference_num_1
11829    ,xet.reference_num_2
11831    ,xet.reference_num_4
11832    ,xet.reference_char_1
11833    ,xet.reference_char_2
11834    ,xet.reference_char_3
11835    ,xet.reference_char_4
11836    ,xet.reference_date_1
11837    ,xet.reference_date_2
11838    ,xet.reference_date_3
11839    ,xet.reference_date_4
11840    ,xet.event_created_by
11841    ,xet.budgetary_control_flag
11842  , l2.LINE_NUMBER  
11843   , l2.TRANSACTION_DESCRIPTION    source_1
11844   , l2.CODE_COMBINATION_ID    source_5
11845   , l2.CC_FUNC_CR_AMT    source_6
11846   , l2.CC_ACCT_LINE_ID    source_8
11847   , l2.CC_FUNC_AMT    source_10
11848   , l2.CURRENCY_CODE    source_11
11849   , l2.CC_FUNC_DR_AMT    source_12
11850   FROM xla_events_gt     xet 
11851   , IGC_CC_EVENT_JE_LINES_V  l2
11852  WHERE xet.event_id between x_first_event_id and x_last_event_id
11853    and xet.event_date between p_pad_start_date and p_pad_end_date
11854    and xet.event_class_code = C_EVENT_CLASS_CODE
11855    and xet.event_status_code <> 'N'   AND l2.event_id      = xet.event_id
11856 ;
11857 
11858 --
11859 BEGIN
11860 IF g_log_enabled THEN
11861    l_log_module := C_DEFAULT_MODULE||'.EventClass_21';
11862 END IF;
11863 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
11864    trace
11865       (p_msg      => 'BEGIN of EventClass_21'
11866       ,p_level    => C_LEVEL_PROCEDURE
11867       ,p_module   => l_log_module);
11868 END IF;
11869 
11870 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
11871    trace
11872       (p_msg      => 'p_application_id = '||p_application_id||
11873                      ' - p_base_ledger_id = '||p_base_ledger_id||
11874                      ' - p_target_ledger_id  = '||p_target_ledger_id||
11875                      ' - p_language = '||p_language||
11876                      ' - p_currency_code = '||p_currency_code||
11877                      ' - p_sla_ledger_id = '||p_sla_ledger_id
11878       ,p_level    => C_LEVEL_STATEMENT
11879       ,p_module   => l_log_module);
11880 END IF;
11881 --
11882 -- initialze arrays
11883 --
11884 g_array_event.DELETE;
11885 l_rec_array_event := l_null_rec_array_event;
11886 --
11887 --------------------------------------
11888 -- 4262811 Initialze MPA Line Number
11889 --------------------------------------
11890 XLA_AE_HEADER_PKG.g_mpa_line_num := 0;
11891 
11892 --
11893 
11894 --
11895 OPEN header_cur;
11896 --
11897 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
11898    trace
11899    (p_msg      => 'SQL - FETCH header_cur'
11900    ,p_level    => C_LEVEL_STATEMENT
11901    ,p_module   => l_log_module);
11902 END IF;
11903 --
11904 LOOP
11905 FETCH header_cur BULK COLLECT INTO
11906         l_array_entity_id
11907       , l_array_legal_entity_id
11908       , l_array_entity_code
11909       , l_array_transaction_num
11910       , l_array_event_id
11911       , l_array_class_code
11912       , l_array_event_type
11913       , l_array_event_number
11914       , l_array_event_date
11915       , l_array_transaction_date
11916       , l_array_reference_num_1
11917       , l_array_reference_num_2
11918       , l_array_reference_num_3
11919       , l_array_reference_num_4
11920       , l_array_reference_char_1
11921       , l_array_reference_char_2
11922       , l_array_reference_char_3
11923       , l_array_reference_char_4
11924       , l_array_reference_date_1
11925       , l_array_reference_date_2
11926       , l_array_reference_date_3
11927       , l_array_reference_date_4
11928       , l_array_event_created_by
11929       , l_array_budgetary_control_flag 
11930       , l_array_source_2
11931       , l_array_source_3
11932       , l_array_source_4
11933       , l_array_source_9
11934       , l_array_source_18
11935       LIMIT l_rows;
11936 --
11937 IF (C_LEVEL_EVENT >= g_log_level) THEN
11938    trace
11939    (p_msg      => '# rows extracted from header extract objects = '||TO_CHAR(header_cur%ROWCOUNT)
11940    ,p_level    => C_LEVEL_EVENT
11941    ,p_module   => l_log_module);
11942 END IF;
11943 --
11944 EXIT WHEN l_array_entity_id.COUNT = 0;
11945 
11946 -- initialize arrays
11947 XLA_AE_HEADER_PKG.g_rec_header_new        := NULL;
11948 XLA_AE_LINES_PKG.g_rec_lines              := NULL;
11949 
11950 --
11951 -- Bug 4458708
11952 --
11953 XLA_AE_LINES_PKG.g_LineNumber := 0;
11954 
11955 
11956 -- 4262811 - when creating Accrual Reversal or MPA, use g_last_hdr_idx to increment for next header id
11957 g_last_hdr_idx := l_array_event_id.LAST;
11958 --
11959 -- loop for the headers. Each iteration is for each header extract row
11960 -- fetched in header cursor
11961 --
11962 FOR hdr_idx IN l_array_event_id.FIRST .. l_array_event_id.LAST LOOP
11963 
11964 --
11965 -- set event info as cache for other routines to refer event attributes
11966 --
11967 XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
11968    (p_application_id           => p_application_id
11969    ,p_primary_ledger_id        => p_primary_ledger_id
11970    ,p_base_ledger_id           => p_base_ledger_id
11971    ,p_target_ledger_id         => p_target_ledger_id
11972    ,p_entity_id                => l_array_entity_id(hdr_idx)
11973    ,p_legal_entity_id          => l_array_legal_entity_id(hdr_idx)
11977    ,p_event_class_code         => l_array_class_code(hdr_idx)
11974    ,p_entity_code              => l_array_entity_code(hdr_idx)
11975    ,p_transaction_num          => l_array_transaction_num(hdr_idx)
11976    ,p_event_id                 => l_array_event_id(hdr_idx)
11978    ,p_event_type_code          => l_array_event_type(hdr_idx)
11979    ,p_event_number             => l_array_event_number(hdr_idx)
11980    ,p_event_date               => l_array_event_date(hdr_idx)
11981    ,p_transaction_date         => l_array_transaction_date(hdr_idx)
11982    ,p_reference_num_1          => l_array_reference_num_1(hdr_idx)
11983    ,p_reference_num_2          => l_array_reference_num_2(hdr_idx)
11984    ,p_reference_num_3          => l_array_reference_num_3(hdr_idx)
11985    ,p_reference_num_4          => l_array_reference_num_4(hdr_idx)
11986    ,p_reference_char_1         => l_array_reference_char_1(hdr_idx)
11987    ,p_reference_char_2         => l_array_reference_char_2(hdr_idx)
11988    ,p_reference_char_3         => l_array_reference_char_3(hdr_idx)
11989    ,p_reference_char_4         => l_array_reference_char_4(hdr_idx)
11990    ,p_reference_date_1         => l_array_reference_date_1(hdr_idx)
11991    ,p_reference_date_2         => l_array_reference_date_2(hdr_idx)
11992    ,p_reference_date_3         => l_array_reference_date_3(hdr_idx)
11993    ,p_reference_date_4         => l_array_reference_date_4(hdr_idx)
11994    ,p_event_created_by         => l_array_event_created_by(hdr_idx)
11995    ,p_budgetary_control_flag   => l_array_budgetary_control_flag(hdr_idx));
11996 
11997 --
11998 -- set the status of entry to C_VALID (0)
11999 --
12000 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status    := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
12001 
12002 --
12003 -- initialize a row for ae header
12004 --
12005 XLA_AE_HEADER_PKG.InitHeader(hdr_idx);
12006 
12007 l_event_id := l_array_event_id(hdr_idx);
12008 
12009 --
12010 -- storing the hdr_idx for event. May be used by line cursor.
12011 --
12012 g_array_event(l_event_id).array_value_num('header_index') := hdr_idx;
12013 
12014 --
12015 -- store sources from header extract. This can be improved to
12016 -- store only those sources from header extract that may be used in lines
12017 --
12018 
12019 g_array_event(l_event_id).array_value_char('source_2') := l_array_source_2(hdr_idx);
12020 g_array_event(l_event_id).array_value_char('source_3') := l_array_source_3(hdr_idx);
12021 g_array_event(l_event_id).array_value_char('source_4') := l_array_source_4(hdr_idx);
12022 g_array_event(l_event_id).array_value_char('source_9') := l_array_source_9(hdr_idx);
12023 g_array_event(l_event_id).array_value_date('source_18') := l_array_source_18(hdr_idx);
12024 
12025 --
12026 -- initilaize the status of ae headers for diffrent balance types
12027 -- the status is initialised to C_NOT_CREATED (2)
12028 --
12029 --g_array_event(l_event_id).array_value_num('actual_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
12030 --g_array_event(l_event_id).array_value_num('budget_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
12031 --g_array_event(l_event_id).array_value_num('encumbrance_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
12032 
12033 --
12034 -- call api to validate and store accounting attributes for header
12035 --
12036 
12037 ------------------------------------------------------------
12038 -- Accrual Reversal : to get date for Standard Source (NONE)
12039 ------------------------------------------------------------
12040 l_acc_rev_gl_date_source := NULL;
12041 
12042      l_rec_acct_attrs.array_acct_attr_code(1)   := 'GL_DATE';
12043       l_rec_acct_attrs.array_date_value(1) := g_array_event(l_event_id).array_value_date('source_18');
12044 
12045 
12046 XLA_AE_HEADER_PKG.SetHdrAcctAttrs(l_rec_acct_attrs);
12047 
12048 XLA_AE_HEADER_PKG.SetJeCategoryName;
12049 
12050 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_type_code(hdr_idx)  := l_array_event_type(hdr_idx);
12051 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_id(hdr_idx)         := l_array_event_id(hdr_idx);
12052 XLA_AE_HEADER_PKG.g_rec_header_new.array_entity_id(hdr_idx)        := l_array_entity_id(hdr_idx);
12053 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_number(hdr_idx)     := l_array_event_number(hdr_idx);
12054 XLA_AE_HEADER_PKG.g_rec_header_new.array_target_ledger_id(hdr_idx) := p_target_ledger_id;
12055 
12056 
12057 --
12058 xla_ae_header_pkg.SetHdrDescription(
12059    p_description => Description_2 (
12060    p_application_id => p_application_id 
12061  , p_source_2 => g_array_event(l_event_id).array_value_char('source_2')
12062  , p_source_3 => g_array_event(l_event_id).array_value_char('source_3')
12063  , p_source_4 => g_array_event(l_event_id).array_value_char('source_4')
12064    )
12065 );
12066 --
12067 
12068 -- No header level analytical criteria
12069 
12070 --
12071 --accounting attribute enhancement, bug 3612931
12072 --
12073 l_trx_reversal_source := SUBSTR(NULL, 1,30);
12074 
12075 IF NVL(l_trx_reversal_source, 'N') NOT IN ('N','Y') THEN
12076    xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
12077 
12078    xla_accounting_err_pkg.build_message
12079       (p_appli_s_name            => 'XLA'
12080       ,p_msg_name                => 'XLA_AP_INVALID_HDR_ATTR'
12081       ,p_token_1                 => 'ACCT_ATTR_NAME'
12082       ,p_value_1                 => xla_ae_sources_pkg.GetAccountingSourceName('TRX_ACCT_REVERSAL_OPTION')
12083       ,p_token_2                 => 'PRODUCT_NAME'
12084       ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
12088 
12085       ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
12086       ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
12087       ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
12089 ELSIF NVL(l_trx_reversal_source, 'N') = 'Y' THEN
12090    --
12091    -- following sets the accounting attributes needed to reverse
12092    -- accounting for a distributeion
12093    --
12094    xla_ae_lines_pkg.SetTrxReversalAttrs
12095       (p_event_id              => l_event_id
12096       ,p_gl_date               => XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(hdr_idx)
12097       ,p_trx_reversal_source   => l_trx_reversal_source);
12098 
12099 END IF;
12100 
12101 
12102 ----------------------------------------------------------------
12103 -- 4262811 -  update the header statuses to invalid in need be
12104 ----------------------------------------------------------------
12105 --
12106 XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus (p_hdr_idx => hdr_idx);
12107 
12108 
12109   -----------------------------------------------
12110   -- No accrual reversal for the event class/type
12111   -----------------------------------------------
12112 ----------------------------------------------------------------
12113 
12114 --
12115 -- this ends the header loop iteration for one bulk fetch
12116 --
12117 END LOOP;
12118 
12119 l_first_event_id   := l_array_event_id(l_array_event_id.FIRST);
12120 l_last_event_id    := l_array_event_id(l_array_event_id.LAST);
12121 
12122 --
12123 -- insert dummy rows into lines gt table that were created due to
12124 -- transaction reversals
12125 --
12126 IF XLA_AE_LINES_PKG.g_rec_lines.array_ae_header_id.COUNT > 0 THEN
12127    l_result := XLA_AE_LINES_PKG.InsertLines;
12128 END IF;
12129 
12130 --
12131 -- reset the temp_line_num for each set of events fetched from header
12132 -- cursor rather than doing it for each new event in line cursor
12133 -- Bug 3939231
12134 --
12135 xla_ae_lines_pkg.g_temp_line_num := 0;
12136 
12137 
12138 
12139 --
12140 OPEN line_cur(x_first_event_id  => l_first_event_id, x_last_event_id  => l_last_event_id);
12141 --
12142 --
12143 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
12144 
12145       trace
12146          (p_msg      => 'SQL - FETCH line_cur'
12147          ,p_level    => C_LEVEL_STATEMENT
12148          ,p_module   => l_log_module);
12149 
12150 END IF;
12151 --
12152 --
12153 LOOP
12154   --
12155   FETCH line_cur BULK COLLECT INTO
12156         l_array_entity_id
12157       , l_array_legal_entity_id
12158       , l_array_entity_code
12159       , l_array_transaction_num
12160       , l_array_event_id
12161       , l_array_class_code
12162       , l_array_event_type
12163       , l_array_event_number
12164       , l_array_event_date
12165       , l_array_transaction_date
12166       , l_array_reference_num_1
12167       , l_array_reference_num_2
12168       , l_array_reference_num_3
12169       , l_array_reference_num_4
12170       , l_array_reference_char_1
12171       , l_array_reference_char_2
12172       , l_array_reference_char_3
12173       , l_array_reference_char_4
12174       , l_array_reference_date_1
12175       , l_array_reference_date_2
12176       , l_array_reference_date_3
12177       , l_array_reference_date_4
12178       , l_array_event_created_by
12179       , l_array_budgetary_control_flag
12180       , l_array_extract_line_num 
12181       , l_array_source_1
12182       , l_array_source_5
12183       , l_array_source_6
12184       , l_array_source_8
12185       , l_array_source_10
12186       , l_array_source_11
12187       , l_array_source_12
12188       LIMIT l_rows;
12189 
12190   --
12191   IF (C_LEVEL_EVENT >= g_log_level) THEN
12192             trace
12196   END IF;
12193                (p_msg      => '# rows extracted from line extract objects = '||TO_CHAR(line_cur%ROWCOUNT)
12194                ,p_level    => C_LEVEL_EVENT
12195                ,p_module   => l_log_module);
12197   --
12198   EXIT WHEN l_array_entity_id.count = 0;
12199 
12200   XLA_AE_LINES_PKG.g_rec_lines := null;
12201 
12202 --
12203 -- Bug 4458708
12204 --
12205 XLA_AE_LINES_PKG.g_LineNumber := 0;
12206 --
12207 --
12208 
12209 FOR Idx IN 1..l_array_event_id.count LOOP
12210    --
12211    -- 5648433 (move l_event_id out of IF statement)  set l_event_id to be used inside IF condition
12212    --
12213    l_event_id := l_array_event_id(idx);  -- 5648433
12214 
12215    --
12216    -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
12217    --
12218 
12219    IF NVL(xla_ae_header_pkg.g_rec_header_new.array_trx_acct_reversal_option
12220              (g_array_event(l_event_id).array_value_num('header_index'))
12221          ,'N'
12222          ) <> 'Y'
12223    THEN
12224       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
12225          trace
12226             (p_msg      => 'Trancaction revesal option is not Y '
12227             ,p_level    => C_LEVEL_STATEMENT
12228             ,p_module   => l_log_module);
12229       END IF;
12230 
12231 --
12232 -- set the XLA_AE_JOURNAL_ENTRY_PKG.g_global_status to C_VALID (0)
12233 --
12234 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
12235 --
12236 -- set event info as cache for other routines to refer event attributes
12237 --
12238 
12239 IF l_event_id <> NVL(l_previous_event_id, -1) THEN
12240    l_previous_event_id := l_event_id;
12241 
12242    XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
12243       (p_application_id           => p_application_id
12244       ,p_primary_ledger_id        => p_primary_ledger_id
12245       ,p_base_ledger_id           => p_base_ledger_id
12246       ,p_target_ledger_id         => p_target_ledger_id
12247       ,p_entity_id                => l_array_entity_id(Idx)
12248       ,p_legal_entity_id          => l_array_legal_entity_id(Idx)
12249       ,p_entity_code              => l_array_entity_code(Idx)
12250       ,p_transaction_num          => l_array_transaction_num(Idx)
12251       ,p_event_id                 => l_array_event_id(Idx)
12252       ,p_event_class_code         => l_array_class_code(Idx)
12253       ,p_event_type_code          => l_array_event_type(Idx)
12254       ,p_event_number             => l_array_event_number(Idx)
12255       ,p_event_date               => l_array_event_date(Idx)
12256       ,p_transaction_date         => l_array_transaction_date(Idx)
12257       ,p_reference_num_1          => l_array_reference_num_1(Idx)
12258       ,p_reference_num_2          => l_array_reference_num_2(Idx)
12259       ,p_reference_num_3          => l_array_reference_num_3(Idx)
12260       ,p_reference_num_4          => l_array_reference_num_4(Idx)
12261       ,p_reference_char_1         => l_array_reference_char_1(Idx)
12262       ,p_reference_char_2         => l_array_reference_char_2(Idx)
12263       ,p_reference_char_3         => l_array_reference_char_3(Idx)
12264       ,p_reference_char_4         => l_array_reference_char_4(Idx)
12265       ,p_reference_date_1         => l_array_reference_date_1(Idx)
12266       ,p_reference_date_2         => l_array_reference_date_2(Idx)
12267       ,p_reference_date_3         => l_array_reference_date_3(Idx)
12268       ,p_reference_date_4         => l_array_reference_date_4(Idx)
12269       ,p_event_created_by         => l_array_event_created_by(Idx)
12270       ,p_budgetary_control_flag   => l_array_budgetary_control_flag(Idx));
12271        --
12272 END IF;
12273 
12274 
12275 
12276 --
12277 xla_ae_lines_pkg.SetExtractLine(p_extract_line => l_array_extract_line_num(Idx));
12278 
12279 l_acct_reversal_source := SUBSTR(NULL, 1,30);
12280 
12281 IF l_continue_with_lines THEN
12282    IF NVL(l_acct_reversal_source, 'N') NOT IN ('N','Y','B') THEN
12283       xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
12284 
12285       xla_accounting_err_pkg.build_message
12286          (p_appli_s_name            => 'XLA'
12287          ,p_msg_name                => 'XLA_AP_INVALID_REVERSAL_OPTION'
12288          ,p_token_1                 => 'LINE_NUMBER'
12289          ,p_value_1                 => l_array_extract_line_num(Idx)
12290          ,p_token_2                 => 'PRODUCT_NAME'
12291          ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
12292          ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
12293          ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
12294          ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
12295 
12296    ELSIF NVL(l_acct_reversal_source, 'N') IN ('Y','B') THEN
12297       --
12298       -- following sets the accounting attributes needed to reverse
12299       -- accounting for a distributeion
12300       --
12301 
12302       --
12303       -- 5217187
12304       --
12305       l_rec_rev_acct_attrs.array_acct_attr_code(1):= 'GL_DATE';
12309       --
12306       l_rec_rev_acct_attrs.array_date_value(1) := XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(
12307                                        g_array_event(l_event_id).array_value_num('header_index'));
12308       --
12310 
12311       -- No reversal code generated
12312 
12313       xla_ae_lines_pkg.SetAcctReversalAttrs
12314          (p_event_id             => l_event_id
12315          ,p_rec_acct_attrs       => l_rec_rev_acct_attrs
12316          ,p_calculate_acctd_flag => l_calculate_acctd_flag
12317          ,p_calculate_g_l_flag   => l_calculate_g_l_flag);
12318    END IF;
12319 
12320    IF NVL(l_acct_reversal_source, 'N') IN ('N','B') THEN
12321        l_actual_flag := NULL;  l_actual_gain_loss_ref := '#####';
12322 
12323 --
12324 AcctLineType_14 (
12325  p_application_id  => p_application_id
12326  ,p_event_id     => l_event_id
12327  ,p_calculate_acctd_flag => l_calculate_acctd_flag
12328  ,p_calculate_g_l_flag => l_calculate_g_l_flag
12329  ,p_actual_flag => l_actual_flag
12330  ,p_balance_type_code => l_balance_type_code
12331  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
12332  
12333  , p_source_1 => l_array_source_1(Idx)
12334  , p_source_5 => l_array_source_5(Idx)
12335  , p_source_6 => l_array_source_6(Idx)
12336  , p_source_8 => l_array_source_8(Idx)
12337  , p_source_9 => g_array_event(l_event_id).array_value_char('source_9')
12338  , p_source_10 => l_array_source_10(Idx)
12339  , p_source_11 => l_array_source_11(Idx)
12340  );
12341 If(l_balance_type_code = 'A') THEN
12342   l_actual_gain_loss_ref := l_gain_or_loss_ref;
12343 END IF;
12344 
12345 --
12346 
12347 
12348 --
12349 AcctLineType_15 (
12350  p_application_id  => p_application_id
12351  ,p_event_id     => l_event_id
12352  ,p_calculate_acctd_flag => l_calculate_acctd_flag
12353  ,p_calculate_g_l_flag => l_calculate_g_l_flag
12354  ,p_actual_flag => l_actual_flag
12355  ,p_balance_type_code => l_balance_type_code
12356  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
12357  
12358  , p_source_1 => l_array_source_1(Idx)
12359  , p_source_5 => l_array_source_5(Idx)
12360  , p_source_8 => l_array_source_8(Idx)
12361  , p_source_9 => g_array_event(l_event_id).array_value_char('source_9')
12362  , p_source_10 => l_array_source_10(Idx)
12363  , p_source_11 => l_array_source_11(Idx)
12364  , p_source_12 => l_array_source_12(Idx)
12365  );
12366 If(l_balance_type_code = 'A') THEN
12367   l_actual_gain_loss_ref := l_gain_or_loss_ref;
12368 END IF;
12369 
12370 --
12371 
12372       -- only execute it if calculate g/l flag is yes, and primary or secondary ledger
12373       -- or secondary ledger that has different currency with primary
12374       -- or alc that is calculated by sla
12375       IF (((l_calculate_g_l_flag = 'Y' AND XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_category_code <> 'ALC') or
12376             (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_category_code in ('ALC', 'SECONDARY') AND XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.calculate_amts_flag='Y'))
12377 
12378 --      IF((l_calculate_g_l_flag='Y' or XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id <>
12379 --                    XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id)
12380           AND (l_actual_flag = 'A')) THEN
12381         XLA_AE_LINES_PKG.CreateGainOrLossLines(
12382           p_event_id         => xla_ae_journal_entry_pkg.g_cache_event.event_id
12383          ,p_application_id   => p_application_id
12384          ,p_amb_context_code => 'DEFAULT'
12385          ,p_entity_code      => xla_ae_journal_entry_pkg.g_cache_event.entity_code
12386          ,p_event_class_code => C_EVENT_CLASS_CODE
12387          ,p_event_type_code  => C_EVENT_TYPE_CODE
12388          
12389          ,p_gain_ccid        => -1
12390          ,p_loss_ccid        => -1
12391 
12392          ,p_actual_flag      => l_actual_flag
12393          ,p_enc_flag         => null
12394          ,p_actual_g_l_ref   => l_actual_gain_loss_ref
12395          ,p_enc_g_l_ref      => null
12396          );
12397       END IF;
12398    END IF;
12399 END IF;
12400 
12401    ELSE
12402       --
12403       -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
12404       --
12405       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
12406          trace
12407             (p_msg      => 'Trancaction revesal option is Y'
12408             ,p_level    => C_LEVEL_STATEMENT
12409             ,p_module   => l_log_module);
12410       END IF;
12411    END IF;
12415 end loop;
12412 
12413 END LOOP;
12414 l_result := XLA_AE_LINES_PKG.InsertLines ;
12416 close line_cur;
12417 
12418 
12419 --
12420 -- insert headers into xla_ae_headers_gt table
12421 --
12422 l_result := XLA_AE_HEADER_PKG.InsertHeaders ;
12423 
12424 -- insert into errors table here.
12425 
12426 END LOOP;
12427 
12428 --
12429 -- 4865292
12430 --
12431 -- Compare g_hdr_extract_count with event count in
12432 -- CreateHeadersAndLines.
12433 --
12434 g_hdr_extract_count := g_hdr_extract_count + header_cur%ROWCOUNT;
12435 
12436 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
12437    trace (p_msg     => '# rows extracted from header extract objects '
12438                     || ' (running total): '
12439                     || g_hdr_extract_count
12440          ,p_level   => C_LEVEL_STATEMENT
12441          ,p_module  => l_log_module);
12442 END IF;
12443 
12444 CLOSE header_cur;
12445 --
12446 
12447 --
12448 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
12449    trace
12450       (p_msg      => 'END of EventClass_21'
12451       ,p_level    => C_LEVEL_PROCEDURE
12452       ,p_module   => l_log_module);
12453 END IF;
12454 --
12455 RETURN l_result;
12456 EXCEPTION
12457 WHEN xla_exceptions_pkg.application_exception THEN
12458    
12459 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
12460 
12461    
12462 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
12463 
12464    RAISE;
12465 WHEN OTHERS THEN
12466    xla_exceptions_pkg.raise_message
12467       (p_location => 'XLA_08407_AAD_S_000013_BC_PKG.EventClass_21');
12468 END EventClass_21;
12469 --
12470 
12471 ---------------------------------------
12472 --
12473 -- PRIVATE PROCEDURE
12474 --         insert_sources_22
12475 --
12476 ----------------------------------------
12477 --
12478 PROCEDURE insert_sources_22(
12479                                 p_target_ledger_id       IN NUMBER
12480                               , p_language               IN VARCHAR2
12481                               , p_sla_ledger_id          IN NUMBER
12482                               , p_pad_start_date         IN DATE
12483                               , p_pad_end_date           IN DATE
12484                          )
12485 IS
12486 
12487 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'CC_REQUISITIONS_ALL';
12488 C_EVENT_CLASS_CODE   CONSTANT  VARCHAR2(30) := 'CC_REQUISITIONS';
12489 p_apps_owner                   VARCHAR2(30);
12490 l_log_module                   VARCHAR2(240);
12491 BEGIN
12492 IF g_log_enabled THEN
12493       l_log_module := C_DEFAULT_MODULE||'.insert_sources_22';
12494 END IF;
12495 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
12496 
12497       trace
12498          (p_msg      => 'BEGIN of insert_sources_22'
12499          ,p_level    => C_LEVEL_PROCEDURE
12500          ,p_module   => l_log_module);
12501 
12502 END IF;
12503 
12504 -- select APPS owner
12505 SELECT oracle_username
12506   INTO p_apps_owner
12507   FROM fnd_oracle_userid
12508  WHERE read_only_flag = 'U'
12509 ;
12510 
12511 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
12512       trace
12513          (p_msg      => 'p_target_ledger_id = '||p_target_ledger_id||
12514                         ' - p_language = '||p_language||
12515                         ' - p_sla_ledger_id  = '||p_sla_ledger_id ||
12516                         ' - p_pad_start_date = '||TO_CHAR(p_pad_start_date)||
12517                         ' - p_pad_end_date = '||TO_CHAR(p_pad_end_date)||
12518                         ' - p_apps_owner = '||TO_CHAR(p_apps_owner)
12519          ,p_level    => C_LEVEL_STATEMENT
12520          ,p_module   => l_log_module);
12524 --
12521 END IF;
12522 
12523 
12525 INSERT INTO xla_diag_sources --hdr2
12526 (
12527         event_id
12528       , ledger_id
12529       , sla_ledger_id
12530       , description_language
12531       , object_name
12532       , object_type_code
12533       , line_number
12534       , source_application_id
12535       , source_type_code
12536       , source_code
12537       , source_value
12538       , source_meaning
12539       , created_by
12540       , creation_date
12541       , last_update_date
12542       , last_updated_by
12543       , last_update_login
12544       , program_update_date
12545       , program_application_id
12546       , program_id
12547       , request_id
12548 )
12549 SELECT
12550         event_id
12551       , p_target_ledger_id
12552       , p_sla_ledger_id
12553       , p_language
12554       , object_name
12555       , object_type_code
12556       , line_number
12557       , source_application_id
12558       , source_type_code
12559       , source_code
12560       , SUBSTR(source_value ,1,1996)
12561       , SUBSTR(source_meaning ,1,200)
12562       , xla_environment_pkg.g_Usr_Id
12563       , TRUNC(SYSDATE)
12564       , TRUNC(SYSDATE)
12565       , xla_environment_pkg.g_Usr_Id
12566       , xla_environment_pkg.g_Login_Id
12567       , TRUNC(SYSDATE)
12568       , xla_environment_pkg.g_Prog_Appl_Id
12569       , xla_environment_pkg.g_Prog_Id
12570       , xla_environment_pkg.g_Req_Id
12571   FROM (
12572        SELECT xet.event_id                  event_id
12573             , 0                          line_number
12574             , CASE r
12575                WHEN 1 THEN 'IGC_CC_EVENT_JE_HEADER_V' 
12576                 WHEN 2 THEN 'IGC_CC_EVENT_JE_HEADER_V' 
12577                 WHEN 3 THEN 'IGC_CC_EVENT_JE_HEADER_V' 
12578                 WHEN 4 THEN 'IGC_CC_EVENT_JE_HEADER_V' 
12579                 WHEN 5 THEN 'IGC_CC_EVENT_JE_HEADER_V' 
12580                 
12581                ELSE null
12582               END                           object_name
12583             , CASE r
12584                 WHEN 1 THEN 'HEADER' 
12585                 WHEN 2 THEN 'HEADER' 
12586                 WHEN 3 THEN 'HEADER' 
12587                 WHEN 4 THEN 'HEADER' 
12588                 WHEN 5 THEN 'HEADER' 
12589                 
12590                 ELSE null
12591               END                           object_type_code
12592             , CASE r
12593                 WHEN 1 THEN '8407' 
12594                 WHEN 2 THEN '8407' 
12595                 WHEN 3 THEN '8407' 
12596                 WHEN 4 THEN '8407' 
12597                 WHEN 5 THEN '8407' 
12598                 
12599                 ELSE null
12600               END                           source_application_id
12601             , 'S'             source_type_code
12602             , CASE r
12603                 WHEN 1 THEN 'HEADER_DESC' 
12604                 WHEN 2 THEN 'REFERENCE_4' 
12605                 WHEN 3 THEN 'REFERENCE_3' 
12606                 WHEN 4 THEN 'DOCUMENT_TYPE' 
12607                 WHEN 5 THEN 'ACCOUNTING_DATE' 
12608                 
12609                 ELSE null
12610               END                           source_code
12611             , CASE r
12612                 WHEN 1 THEN TO_CHAR(h1.HEADER_DESC)
12613                 WHEN 2 THEN TO_CHAR(h1.REFERENCE_4)
12614                 WHEN 3 THEN TO_CHAR(h1.REFERENCE_3)
12615                 WHEN 4 THEN TO_CHAR(h1.DOCUMENT_TYPE)
12616                 WHEN 5 THEN TO_CHAR(h1.ACCOUNTING_DATE)
12617                 
12618                 ELSE null
12619               END                           source_value
12620             , null              source_meaning
12621          FROM xla_events_gt     xet  
12622       , IGC_CC_EVENT_JE_HEADER_V  h1
12623              ,(select rownum r from all_objects where rownum <= 5 and owner = p_apps_owner)
12624          WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
12625            AND xet.event_class_code = C_EVENT_CLASS_CODE
12626               AND h1.event_id = xet.event_id
12627 
12631 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
12628 )
12629 ;
12630 --
12632 
12633       trace
12634          (p_msg      => 'number of header sources inserted = '||SQL%ROWCOUNT
12635          ,p_level    => C_LEVEL_STATEMENT
12636          ,p_module   => l_log_module);
12637 
12638 END IF;
12639 --
12640 
12641 
12642 
12643 --
12644 INSERT INTO xla_diag_sources  --line2
12645 (
12646         event_id
12647       , ledger_id
12648       , sla_ledger_id
12649       , description_language
12650       , object_name
12651       , object_type_code
12652       , line_number
12653       , source_application_id
12654       , source_type_code
12655       , source_code
12656       , source_value
12657       , source_meaning
12658       , created_by
12659       , creation_date
12660       , last_update_date
12661       , last_updated_by
12662       , last_update_login
12663       , program_update_date
12664       , program_application_id
12665       , program_id
12666       , request_id
12667 )
12668 SELECT  event_id
12669       , p_target_ledger_id
12670       , p_sla_ledger_id
12671       , p_language
12672       , object_name
12673       , object_type_code
12674       , line_number
12675       , source_application_id
12676       , source_type_code
12677       , source_code
12678       , SUBSTR(source_value,1,1996)
12679       , SUBSTR(source_meaning ,1,200)
12680       , xla_environment_pkg.g_Usr_Id
12681       , TRUNC(SYSDATE)
12682       , TRUNC(SYSDATE)
12683       , xla_environment_pkg.g_Usr_Id
12684       , xla_environment_pkg.g_Login_Id
12685       , TRUNC(SYSDATE)
12686       , xla_environment_pkg.g_Prog_Appl_Id
12687       , xla_environment_pkg.g_Prog_Id
12688       , xla_environment_pkg.g_Req_Id
12689   FROM (
12690        SELECT xet.event_id                  event_id
12691             , l2.line_number                 line_number
12692             , CASE r
12693                WHEN 1 THEN 'IGC_CC_EVENT_JE_LINES_V' 
12694                 WHEN 2 THEN 'IGC_CC_EVENT_JE_LINES_V' 
12695                 WHEN 3 THEN 'IGC_CC_EVENT_JE_LINES_V' 
12696                 WHEN 4 THEN 'IGC_CC_EVENT_JE_LINES_V' 
12697                 WHEN 5 THEN 'IGC_CC_EVENT_JE_LINES_V' 
12698                 WHEN 6 THEN 'IGC_CC_EVENT_JE_LINES_V' 
12699                 WHEN 7 THEN 'IGC_CC_EVENT_JE_LINES_V' 
12700                 
12701                ELSE null
12702               END                           object_name
12703             , CASE r
12704                 WHEN 1 THEN 'LINE' 
12705                 WHEN 2 THEN 'LINE' 
12706                 WHEN 3 THEN 'LINE' 
12707                 WHEN 4 THEN 'LINE' 
12708                 WHEN 5 THEN 'LINE' 
12709                 WHEN 6 THEN 'LINE' 
12710                 WHEN 7 THEN 'LINE' 
12711                 
12712                 ELSE null
12713               END                           object_type_code
12714             , CASE r
12718                 WHEN 4 THEN '8407' 
12715                 WHEN 1 THEN '8407' 
12716                 WHEN 2 THEN '8407' 
12717                 WHEN 3 THEN '8407' 
12719                 WHEN 5 THEN '8407' 
12720                 WHEN 6 THEN '8407' 
12721                 WHEN 7 THEN '8407' 
12722                 
12723                 ELSE null
12724               END                           source_application_id
12725             , 'S'             source_type_code
12726             , CASE r
12727                 WHEN 1 THEN 'TRANSACTION_DESCRIPTION' 
12728                 WHEN 2 THEN 'CODE_COMBINATION_ID' 
12729                 WHEN 3 THEN 'CC_FUNC_CR_AMT' 
12730                 WHEN 4 THEN 'CC_ACCT_LINE_ID' 
12731                 WHEN 5 THEN 'CC_FUNC_AMT' 
12732                 WHEN 6 THEN 'CURRENCY_CODE' 
12733                 WHEN 7 THEN 'CC_FUNC_DR_AMT' 
12734                 
12735                 ELSE null
12736               END                           source_code
12737             , CASE r
12738                 WHEN 1 THEN TO_CHAR(l2.TRANSACTION_DESCRIPTION)
12739                 WHEN 2 THEN TO_CHAR(l2.CODE_COMBINATION_ID)
12740                 WHEN 3 THEN TO_CHAR(l2.CC_FUNC_CR_AMT)
12741                 WHEN 4 THEN TO_CHAR(l2.CC_ACCT_LINE_ID)
12742                 WHEN 5 THEN TO_CHAR(l2.CC_FUNC_AMT)
12743                 WHEN 6 THEN TO_CHAR(l2.CURRENCY_CODE)
12744                 WHEN 7 THEN TO_CHAR(l2.CC_FUNC_DR_AMT)
12745                 
12746                 ELSE null
12747               END                           source_value
12748             , null              source_meaning
12749          FROM  xla_events_gt     xet  
12750         , IGC_CC_EVENT_JE_LINES_V  l2
12751             , (select rownum r from all_objects where rownum <= 7 and owner = p_apps_owner)
12752         WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
12753           AND xet.event_class_code = C_EVENT_CLASS_CODE
12754             AND l2.event_id          = xet.event_id
12755 
12756 )
12757 ;
12758 --
12759 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
12760 
12761       trace
12762          (p_msg      => 'number of line sources inserted = '||SQL%ROWCOUNT
12763          ,p_level    => C_LEVEL_STATEMENT
12764          ,p_module   => l_log_module);
12765 
12766 END IF;
12767 
12768 
12769 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
12770       trace
12771          (p_msg      => 'END of insert_sources_22'
12772          ,p_level    => C_LEVEL_PROCEDURE
12773          ,p_module   => l_log_module);
12774 END IF;
12775 EXCEPTION
12776   WHEN xla_exceptions_pkg.application_exception THEN
12777       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
12778             trace
12779                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
12780                ,p_level    => C_LEVEL_EXCEPTION
12781                ,p_module   => l_log_module);
12782       END IF;
12783       RAISE;
12784   WHEN OTHERS THEN
12785       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
12786             trace
12787                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
12788                ,p_level    => C_LEVEL_EXCEPTION
12789                ,p_module   => l_log_module);
12790        END IF;
12791        xla_exceptions_pkg.raise_message
12792            (p_location => 'XLA_08407_AAD_S_000013_BC_PKG.insert_sources_22');
12793 END insert_sources_22;
12794 --
12795 
12796 ---------------------------------------
12797 --
12798 -- PRIVATE FUNCTION
12799 --         EventClass_22
12800 --
12801 ----------------------------------------
12802 --
12803 FUNCTION EventClass_22
12804        (p_application_id         IN NUMBER
12805        ,p_base_ledger_id         IN NUMBER
12806        ,p_target_ledger_id       IN NUMBER
12807        ,p_language               IN VARCHAR2
12808        ,p_currency_code          IN VARCHAR2
12809        ,p_sla_ledger_id          IN NUMBER
12810        ,p_pad_start_date         IN DATE
12811        ,p_pad_end_date           IN DATE
12812        ,p_primary_ledger_id      IN NUMBER)
12813 RETURN BOOLEAN IS
12814 --
12815 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'CC_REQUISITIONS_ALL';
12816 C_EVENT_CLASS_CODE    CONSTANT  VARCHAR2(30) := 'CC_REQUISITIONS';
12817 
12818 l_calculate_acctd_flag   VARCHAR2(1) :='N';
12819 l_calculate_g_l_flag     VARCHAR2(1) :='N';
12820 --
12821 l_array_legal_entity_id                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
12822 l_array_entity_id                      XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
12823 l_array_entity_code                    XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
12824 l_array_transaction_num                XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
12825 l_array_event_id                       XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
12826 l_array_class_code                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
12827 l_array_event_type                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
12828 l_array_event_number                   XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
12829 l_array_event_date                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
12830 l_array_transaction_date               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
12831 l_array_reference_num_1                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
12832 l_array_reference_num_2                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
12833 l_array_reference_num_3                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
12834 l_array_reference_num_4                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
12838 l_array_reference_char_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
12835 l_array_reference_char_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
12836 l_array_reference_char_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
12837 l_array_reference_char_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
12839 l_array_reference_date_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
12840 l_array_reference_date_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
12841 l_array_reference_date_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
12842 l_array_reference_date_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
12843 l_array_event_created_by               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V100L;
12844 l_array_budgetary_control_flag         XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
12845 
12846 l_event_id                             NUMBER;
12847 l_previous_event_id                    NUMBER;
12848 l_first_event_id                       NUMBER;
12849 l_last_event_id                        NUMBER;
12850 
12851 l_rec_acct_attrs                       XLA_AE_HEADER_PKG.t_rec_acct_attrs;
12852 l_rec_rev_acct_attrs                   XLA_AE_LINES_PKG.t_rec_acct_attrs;
12853 --
12854 --
12855 l_result                    BOOLEAN := TRUE;
12856 l_rows                      NUMBER  := 1000;
12857 l_event_type_name           VARCHAR2(80) := 'All';
12858 l_event_class_name          VARCHAR2(80) := 'CC Requisitions';
12859 l_description               VARCHAR2(4000);
12860 l_transaction_reversal      NUMBER;
12861 l_ae_header_id              NUMBER;
12862 l_array_extract_line_num    xla_ae_journal_entry_pkg.t_array_Num;
12863 l_log_module                VARCHAR2(240);
12864 --
12865 l_acct_reversal_source      VARCHAR2(30);
12866 l_trx_reversal_source       VARCHAR2(30);
12867 
12868 l_continue_with_lines       BOOLEAN := TRUE;
12869 --
12870 l_acc_rev_gl_date_source    DATE;                      -- 4262811
12871 --
12872 type t_array_event_id is table of number index by binary_integer;
12873 
12874 l_rec_array_event                    t_rec_array_event;
12875 l_null_rec_array_event               t_rec_array_event;
12876 l_array_ae_header_id                 xla_number_array_type;
12877 l_actual_flag                        VARCHAR2(1) := NULL;
12878 l_actual_gain_loss_ref               VARCHAR2(30) := '#####';
12879 l_balance_type_code                  VARCHAR2(1) :=NULL;
12880 l_gain_or_loss_ref                   VARCHAR2(30) :=NULL;
12881 
12882 --
12883 TYPE t_array_lookup_meaning IS TABLE OF fnd_lookup_values.meaning%TYPE INDEX BY BINARY_INTEGER;
12884 --
12885 
12886 TYPE t_array_source_2 IS TABLE OF IGC_CC_EVENT_JE_HEADER_V.HEADER_DESC%TYPE INDEX BY BINARY_INTEGER;
12887 TYPE t_array_source_3 IS TABLE OF IGC_CC_EVENT_JE_HEADER_V.REFERENCE_4%TYPE INDEX BY BINARY_INTEGER;
12888 TYPE t_array_source_4 IS TABLE OF IGC_CC_EVENT_JE_HEADER_V.REFERENCE_3%TYPE INDEX BY BINARY_INTEGER;
12889 TYPE t_array_source_9 IS TABLE OF IGC_CC_EVENT_JE_HEADER_V.DOCUMENT_TYPE%TYPE INDEX BY BINARY_INTEGER;
12890 TYPE t_array_source_18 IS TABLE OF IGC_CC_EVENT_JE_HEADER_V.ACCOUNTING_DATE%TYPE INDEX BY BINARY_INTEGER;
12891 
12892 TYPE t_array_source_1 IS TABLE OF IGC_CC_EVENT_JE_LINES_V.TRANSACTION_DESCRIPTION%TYPE INDEX BY BINARY_INTEGER;
12893 TYPE t_array_source_5 IS TABLE OF IGC_CC_EVENT_JE_LINES_V.CODE_COMBINATION_ID%TYPE INDEX BY BINARY_INTEGER;
12894 TYPE t_array_source_6 IS TABLE OF IGC_CC_EVENT_JE_LINES_V.CC_FUNC_CR_AMT%TYPE INDEX BY BINARY_INTEGER;
12895 TYPE t_array_source_8 IS TABLE OF IGC_CC_EVENT_JE_LINES_V.CC_ACCT_LINE_ID%TYPE INDEX BY BINARY_INTEGER;
12896 TYPE t_array_source_10 IS TABLE OF IGC_CC_EVENT_JE_LINES_V.CC_FUNC_AMT%TYPE INDEX BY BINARY_INTEGER;
12897 TYPE t_array_source_11 IS TABLE OF IGC_CC_EVENT_JE_LINES_V.CURRENCY_CODE%TYPE INDEX BY BINARY_INTEGER;
12898 TYPE t_array_source_12 IS TABLE OF IGC_CC_EVENT_JE_LINES_V.CC_FUNC_DR_AMT%TYPE INDEX BY BINARY_INTEGER;
12899 
12900 l_array_source_2              t_array_source_2;
12901 l_array_source_3              t_array_source_3;
12905 
12902 l_array_source_4              t_array_source_4;
12903 l_array_source_9              t_array_source_9;
12904 l_array_source_18              t_array_source_18;
12906 l_array_source_1      t_array_source_1;
12907 l_array_source_5      t_array_source_5;
12908 l_array_source_6      t_array_source_6;
12909 l_array_source_8      t_array_source_8;
12910 l_array_source_10      t_array_source_10;
12911 l_array_source_11      t_array_source_11;
12912 l_array_source_12      t_array_source_12;
12913 
12914 --
12915 CURSOR header_cur
12916 IS
12917 SELECT /*+ leading(xet) cardinality(xet,1) */
12918 -- Event Class Code: CC_REQUISITIONS
12919     xet.entity_id
12920    ,xet.legal_entity_id
12921    ,xet.entity_code
12922    ,xet.transaction_number
12923    ,xet.event_id
12924    ,xet.event_class_code
12925    ,xet.event_type_code
12926    ,xet.event_number
12927    ,xet.event_date
12928    ,xet.transaction_date
12929    ,xet.reference_num_1
12930    ,xet.reference_num_2
12931    ,xet.reference_num_3
12932    ,xet.reference_num_4
12933    ,xet.reference_char_1
12934    ,xet.reference_char_2
12935    ,xet.reference_char_3
12936    ,xet.reference_char_4
12937    ,xet.reference_date_1
12938    ,xet.reference_date_2
12939    ,xet.reference_date_3
12940    ,xet.reference_date_4
12941    ,xet.event_created_by
12942    ,xet.budgetary_control_flag 
12943   , h1.HEADER_DESC    source_2
12944   , h1.REFERENCE_4    source_3
12945   , h1.REFERENCE_3    source_4
12946   , h1.DOCUMENT_TYPE    source_9
12947   , h1.ACCOUNTING_DATE    source_18
12948   FROM xla_events_gt     xet 
12949   , IGC_CC_EVENT_JE_HEADER_V  h1
12950  WHERE xet.event_date between p_pad_start_date and p_pad_end_date
12951    and xet.event_class_code = C_EVENT_CLASS_CODE
12952    and xet.event_status_code <> 'N'  AND h1.event_id = xet.event_id
12953 
12954  ORDER BY event_id
12955 ;
12956 
12957 
12958 --
12959 CURSOR line_cur (x_first_event_id    in number, x_last_event_id    in number)
12960 IS
12961 SELECT  /*+ leading(xet) cardinality(xet,1) */
12962 -- Event Class Code: CC_REQUISITIONS
12963     xet.entity_id
12964    ,xet.legal_entity_id
12965    ,xet.entity_code
12966    ,xet.transaction_number
12967    ,xet.event_id
12968    ,xet.event_class_code
12969    ,xet.event_type_code
12970    ,xet.event_number
12971    ,xet.event_date
12972    ,xet.transaction_date
12973    ,xet.reference_num_1
12974    ,xet.reference_num_2
12975    ,xet.reference_num_3
12976    ,xet.reference_num_4
12977    ,xet.reference_char_1
12978    ,xet.reference_char_2
12979    ,xet.reference_char_3
12980    ,xet.reference_char_4
12981    ,xet.reference_date_1
12982    ,xet.reference_date_2
12983    ,xet.reference_date_3
12984    ,xet.reference_date_4
12985    ,xet.event_created_by
12986    ,xet.budgetary_control_flag
12987  , l2.LINE_NUMBER  
12988   , l2.TRANSACTION_DESCRIPTION    source_1
12989   , l2.CODE_COMBINATION_ID    source_5
12990   , l2.CC_FUNC_CR_AMT    source_6
12991   , l2.CC_ACCT_LINE_ID    source_8
12992   , l2.CC_FUNC_AMT    source_10
12993   , l2.CURRENCY_CODE    source_11
12994   , l2.CC_FUNC_DR_AMT    source_12
12995   FROM xla_events_gt     xet 
12996   , IGC_CC_EVENT_JE_LINES_V  l2
12997  WHERE xet.event_id between x_first_event_id and x_last_event_id
12998    and xet.event_date between p_pad_start_date and p_pad_end_date
12999    and xet.event_class_code = C_EVENT_CLASS_CODE
13000    and xet.event_status_code <> 'N'   AND l2.event_id      = xet.event_id
13001 ;
13002 
13003 --
13004 BEGIN
13005 IF g_log_enabled THEN
13006    l_log_module := C_DEFAULT_MODULE||'.EventClass_22';
13007 END IF;
13008 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
13009    trace
13010       (p_msg      => 'BEGIN of EventClass_22'
13011       ,p_level    => C_LEVEL_PROCEDURE
13012       ,p_module   => l_log_module);
13013 END IF;
13014 
13015 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
13016    trace
13017       (p_msg      => 'p_application_id = '||p_application_id||
13018                      ' - p_base_ledger_id = '||p_base_ledger_id||
13019                      ' - p_target_ledger_id  = '||p_target_ledger_id||
13020                      ' - p_language = '||p_language||
13021                      ' - p_currency_code = '||p_currency_code||
13022                      ' - p_sla_ledger_id = '||p_sla_ledger_id
13023       ,p_level    => C_LEVEL_STATEMENT
13024       ,p_module   => l_log_module);
13025 END IF;
13026 --
13027 -- initialze arrays
13028 --
13029 g_array_event.DELETE;
13030 l_rec_array_event := l_null_rec_array_event;
13031 --
13032 --------------------------------------
13033 -- 4262811 Initialze MPA Line Number
13034 --------------------------------------
13035 XLA_AE_HEADER_PKG.g_mpa_line_num := 0;
13036 
13037 --
13038 
13039 --
13040 OPEN header_cur;
13041 --
13042 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
13043    trace
13044    (p_msg      => 'SQL - FETCH header_cur'
13045    ,p_level    => C_LEVEL_STATEMENT
13046    ,p_module   => l_log_module);
13047 END IF;
13048 --
13049 LOOP
13050 FETCH header_cur BULK COLLECT INTO
13051         l_array_entity_id
13052       , l_array_legal_entity_id
13053       , l_array_entity_code
13054       , l_array_transaction_num
13055       , l_array_event_id
13056       , l_array_class_code
13057       , l_array_event_type
13058       , l_array_event_number
13059       , l_array_event_date
13060       , l_array_transaction_date
13061       , l_array_reference_num_1
13062       , l_array_reference_num_2
13063       , l_array_reference_num_3
13064       , l_array_reference_num_4
13065       , l_array_reference_char_1
13066       , l_array_reference_char_2
13067       , l_array_reference_char_3
13068       , l_array_reference_char_4
13069       , l_array_reference_date_1
13070       , l_array_reference_date_2
13071       , l_array_reference_date_3
13072       , l_array_reference_date_4
13073       , l_array_event_created_by
13074       , l_array_budgetary_control_flag 
13075       , l_array_source_2
13076       , l_array_source_3
13077       , l_array_source_4
13078       , l_array_source_9
13079       , l_array_source_18
13080       LIMIT l_rows;
13081 --
13082 IF (C_LEVEL_EVENT >= g_log_level) THEN
13083    trace
13084    (p_msg      => '# rows extracted from header extract objects = '||TO_CHAR(header_cur%ROWCOUNT)
13085    ,p_level    => C_LEVEL_EVENT
13086    ,p_module   => l_log_module);
13087 END IF;
13088 --
13089 EXIT WHEN l_array_entity_id.COUNT = 0;
13090 
13091 -- initialize arrays
13092 XLA_AE_HEADER_PKG.g_rec_header_new        := NULL;
13093 XLA_AE_LINES_PKG.g_rec_lines              := NULL;
13094 
13095 --
13096 -- Bug 4458708
13097 --
13098 XLA_AE_LINES_PKG.g_LineNumber := 0;
13099 
13100 
13101 -- 4262811 - when creating Accrual Reversal or MPA, use g_last_hdr_idx to increment for next header id
13102 g_last_hdr_idx := l_array_event_id.LAST;
13103 --
13104 -- loop for the headers. Each iteration is for each header extract row
13105 -- fetched in header cursor
13106 --
13107 FOR hdr_idx IN l_array_event_id.FIRST .. l_array_event_id.LAST LOOP
13108 
13109 --
13110 -- set event info as cache for other routines to refer event attributes
13111 --
13112 XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
13113    (p_application_id           => p_application_id
13114    ,p_primary_ledger_id        => p_primary_ledger_id
13115    ,p_base_ledger_id           => p_base_ledger_id
13116    ,p_target_ledger_id         => p_target_ledger_id
13117    ,p_entity_id                => l_array_entity_id(hdr_idx)
13118    ,p_legal_entity_id          => l_array_legal_entity_id(hdr_idx)
13119    ,p_entity_code              => l_array_entity_code(hdr_idx)
13120    ,p_transaction_num          => l_array_transaction_num(hdr_idx)
13121    ,p_event_id                 => l_array_event_id(hdr_idx)
13122    ,p_event_class_code         => l_array_class_code(hdr_idx)
13123    ,p_event_type_code          => l_array_event_type(hdr_idx)
13124    ,p_event_number             => l_array_event_number(hdr_idx)
13125    ,p_event_date               => l_array_event_date(hdr_idx)
13126    ,p_transaction_date         => l_array_transaction_date(hdr_idx)
13127    ,p_reference_num_1          => l_array_reference_num_1(hdr_idx)
13128    ,p_reference_num_2          => l_array_reference_num_2(hdr_idx)
13129    ,p_reference_num_3          => l_array_reference_num_3(hdr_idx)
13130    ,p_reference_num_4          => l_array_reference_num_4(hdr_idx)
13131    ,p_reference_char_1         => l_array_reference_char_1(hdr_idx)
13132    ,p_reference_char_2         => l_array_reference_char_2(hdr_idx)
13133    ,p_reference_char_3         => l_array_reference_char_3(hdr_idx)
13134    ,p_reference_char_4         => l_array_reference_char_4(hdr_idx)
13135    ,p_reference_date_1         => l_array_reference_date_1(hdr_idx)
13136    ,p_reference_date_2         => l_array_reference_date_2(hdr_idx)
13137    ,p_reference_date_3         => l_array_reference_date_3(hdr_idx)
13138    ,p_reference_date_4         => l_array_reference_date_4(hdr_idx)
13139    ,p_event_created_by         => l_array_event_created_by(hdr_idx)
13140    ,p_budgetary_control_flag   => l_array_budgetary_control_flag(hdr_idx));
13141 
13142 --
13143 -- set the status of entry to C_VALID (0)
13144 --
13145 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status    := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
13146 
13147 --
13148 -- initialize a row for ae header
13149 --
13150 XLA_AE_HEADER_PKG.InitHeader(hdr_idx);
13151 
13152 l_event_id := l_array_event_id(hdr_idx);
13153 
13154 --
13155 -- storing the hdr_idx for event. May be used by line cursor.
13156 --
13157 g_array_event(l_event_id).array_value_num('header_index') := hdr_idx;
13158 
13159 --
13160 -- store sources from header extract. This can be improved to
13161 -- store only those sources from header extract that may be used in lines
13162 --
13163 
13164 g_array_event(l_event_id).array_value_char('source_2') := l_array_source_2(hdr_idx);
13165 g_array_event(l_event_id).array_value_char('source_3') := l_array_source_3(hdr_idx);
13166 g_array_event(l_event_id).array_value_char('source_4') := l_array_source_4(hdr_idx);
13167 g_array_event(l_event_id).array_value_char('source_9') := l_array_source_9(hdr_idx);
13168 g_array_event(l_event_id).array_value_date('source_18') := l_array_source_18(hdr_idx);
13169 
13170 --
13171 -- initilaize the status of ae headers for diffrent balance types
13172 -- the status is initialised to C_NOT_CREATED (2)
13173 --
13174 --g_array_event(l_event_id).array_value_num('actual_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
13175 --g_array_event(l_event_id).array_value_num('budget_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
13176 --g_array_event(l_event_id).array_value_num('encumbrance_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
13177 
13178 --
13179 -- call api to validate and store accounting attributes for header
13180 --
13181 
13182 ------------------------------------------------------------
13183 -- Accrual Reversal : to get date for Standard Source (NONE)
13184 ------------------------------------------------------------
13185 l_acc_rev_gl_date_source := NULL;
13186 
13187      l_rec_acct_attrs.array_acct_attr_code(1)   := 'GL_DATE';
13188       l_rec_acct_attrs.array_date_value(1) := g_array_event(l_event_id).array_value_date('source_18');
13189 
13190 
13191 XLA_AE_HEADER_PKG.SetHdrAcctAttrs(l_rec_acct_attrs);
13192 
13193 XLA_AE_HEADER_PKG.SetJeCategoryName;
13194 
13195 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_type_code(hdr_idx)  := l_array_event_type(hdr_idx);
13196 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_id(hdr_idx)         := l_array_event_id(hdr_idx);
13197 XLA_AE_HEADER_PKG.g_rec_header_new.array_entity_id(hdr_idx)        := l_array_entity_id(hdr_idx);
13198 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_number(hdr_idx)     := l_array_event_number(hdr_idx);
13199 XLA_AE_HEADER_PKG.g_rec_header_new.array_target_ledger_id(hdr_idx) := p_target_ledger_id;
13200 
13201 
13202 --
13203 xla_ae_header_pkg.SetHdrDescription(
13204    p_description => Description_2 (
13205    p_application_id => p_application_id 
13206  , p_source_2 => g_array_event(l_event_id).array_value_char('source_2')
13207  , p_source_3 => g_array_event(l_event_id).array_value_char('source_3')
13208  , p_source_4 => g_array_event(l_event_id).array_value_char('source_4')
13209    )
13210 );
13211 --
13212 
13213 -- No header level analytical criteria
13214 
13215 --
13216 --accounting attribute enhancement, bug 3612931
13217 --
13218 l_trx_reversal_source := SUBSTR(NULL, 1,30);
13219 
13220 IF NVL(l_trx_reversal_source, 'N') NOT IN ('N','Y') THEN
13221    xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
13222 
13223    xla_accounting_err_pkg.build_message
13224       (p_appli_s_name            => 'XLA'
13225       ,p_msg_name                => 'XLA_AP_INVALID_HDR_ATTR'
13226       ,p_token_1                 => 'ACCT_ATTR_NAME'
13227       ,p_value_1                 => xla_ae_sources_pkg.GetAccountingSourceName('TRX_ACCT_REVERSAL_OPTION')
13228       ,p_token_2                 => 'PRODUCT_NAME'
13229       ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
13230       ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
13231       ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
13232       ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
13233 
13234 ELSIF NVL(l_trx_reversal_source, 'N') = 'Y' THEN
13235    --
13236    -- following sets the accounting attributes needed to reverse
13237    -- accounting for a distributeion
13238    --
13239    xla_ae_lines_pkg.SetTrxReversalAttrs
13240       (p_event_id              => l_event_id
13241       ,p_gl_date               => XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(hdr_idx)
13242       ,p_trx_reversal_source   => l_trx_reversal_source);
13243 
13244 END IF;
13245 
13246 
13247 ----------------------------------------------------------------
13248 -- 4262811 -  update the header statuses to invalid in need be
13249 ----------------------------------------------------------------
13250 --
13251 XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus (p_hdr_idx => hdr_idx);
13252 
13253 
13254   -----------------------------------------------
13255   -- No accrual reversal for the event class/type
13256   -----------------------------------------------
13257 ----------------------------------------------------------------
13258 
13259 --
13263 
13260 -- this ends the header loop iteration for one bulk fetch
13261 --
13262 END LOOP;
13264 l_first_event_id   := l_array_event_id(l_array_event_id.FIRST);
13265 l_last_event_id    := l_array_event_id(l_array_event_id.LAST);
13266 
13267 --
13268 -- insert dummy rows into lines gt table that were created due to
13269 -- transaction reversals
13270 --
13271 IF XLA_AE_LINES_PKG.g_rec_lines.array_ae_header_id.COUNT > 0 THEN
13272    l_result := XLA_AE_LINES_PKG.InsertLines;
13273 END IF;
13274 
13275 --
13276 -- reset the temp_line_num for each set of events fetched from header
13277 -- cursor rather than doing it for each new event in line cursor
13278 -- Bug 3939231
13279 --
13280 xla_ae_lines_pkg.g_temp_line_num := 0;
13281 
13282 
13283 
13284 --
13285 OPEN line_cur(x_first_event_id  => l_first_event_id, x_last_event_id  => l_last_event_id);
13286 --
13287 --
13288 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
13289 
13290       trace
13291          (p_msg      => 'SQL - FETCH line_cur'
13292          ,p_level    => C_LEVEL_STATEMENT
13293          ,p_module   => l_log_module);
13294 
13295 END IF;
13296 --
13297 --
13298 LOOP
13299   --
13300   FETCH line_cur BULK COLLECT INTO
13301         l_array_entity_id
13302       , l_array_legal_entity_id
13303       , l_array_entity_code
13304       , l_array_transaction_num
13305       , l_array_event_id
13306       , l_array_class_code
13307       , l_array_event_type
13308       , l_array_event_number
13309       , l_array_event_date
13310       , l_array_transaction_date
13311       , l_array_reference_num_1
13312       , l_array_reference_num_2
13313       , l_array_reference_num_3
13314       , l_array_reference_num_4
13315       , l_array_reference_char_1
13316       , l_array_reference_char_2
13317       , l_array_reference_char_3
13318       , l_array_reference_char_4
13319       , l_array_reference_date_1
13320       , l_array_reference_date_2
13321       , l_array_reference_date_3
13322       , l_array_reference_date_4
13323       , l_array_event_created_by
13324       , l_array_budgetary_control_flag
13325       , l_array_extract_line_num 
13326       , l_array_source_1
13327       , l_array_source_5
13328       , l_array_source_6
13329       , l_array_source_8
13330       , l_array_source_10
13331       , l_array_source_11
13332       , l_array_source_12
13333       LIMIT l_rows;
13334 
13335   --
13336   IF (C_LEVEL_EVENT >= g_log_level) THEN
13337             trace
13338                (p_msg      => '# rows extracted from line extract objects = '||TO_CHAR(line_cur%ROWCOUNT)
13339                ,p_level    => C_LEVEL_EVENT
13340                ,p_module   => l_log_module);
13341   END IF;
13342   --
13343   EXIT WHEN l_array_entity_id.count = 0;
13344 
13345   XLA_AE_LINES_PKG.g_rec_lines := null;
13346 
13347 --
13348 -- Bug 4458708
13349 --
13350 XLA_AE_LINES_PKG.g_LineNumber := 0;
13351 --
13352 --
13353 
13354 FOR Idx IN 1..l_array_event_id.count LOOP
13355    --
13356    -- 5648433 (move l_event_id out of IF statement)  set l_event_id to be used inside IF condition
13357    --
13358    l_event_id := l_array_event_id(idx);  -- 5648433
13359 
13360    --
13361    -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
13362    --
13363 
13364    IF NVL(xla_ae_header_pkg.g_rec_header_new.array_trx_acct_reversal_option
13365              (g_array_event(l_event_id).array_value_num('header_index'))
13366          ,'N'
13367          ) <> 'Y'
13368    THEN
13369       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
13370          trace
13371             (p_msg      => 'Trancaction revesal option is not Y '
13372             ,p_level    => C_LEVEL_STATEMENT
13373             ,p_module   => l_log_module);
13374       END IF;
13375 
13376 --
13377 -- set the XLA_AE_JOURNAL_ENTRY_PKG.g_global_status to C_VALID (0)
13378 --
13379 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
13380 --
13381 -- set event info as cache for other routines to refer event attributes
13382 --
13383 
13384 IF l_event_id <> NVL(l_previous_event_id, -1) THEN
13385    l_previous_event_id := l_event_id;
13386 
13387    XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
13388       (p_application_id           => p_application_id
13389       ,p_primary_ledger_id        => p_primary_ledger_id
13390       ,p_base_ledger_id           => p_base_ledger_id
13391       ,p_target_ledger_id         => p_target_ledger_id
13392       ,p_entity_id                => l_array_entity_id(Idx)
13393       ,p_legal_entity_id          => l_array_legal_entity_id(Idx)
13394       ,p_entity_code              => l_array_entity_code(Idx)
13395       ,p_transaction_num          => l_array_transaction_num(Idx)
13396       ,p_event_id                 => l_array_event_id(Idx)
13397       ,p_event_class_code         => l_array_class_code(Idx)
13398       ,p_event_type_code          => l_array_event_type(Idx)
13399       ,p_event_number             => l_array_event_number(Idx)
13400       ,p_event_date               => l_array_event_date(Idx)
13401       ,p_transaction_date         => l_array_transaction_date(Idx)
13402       ,p_reference_num_1          => l_array_reference_num_1(Idx)
13403       ,p_reference_num_2          => l_array_reference_num_2(Idx)
13404       ,p_reference_num_3          => l_array_reference_num_3(Idx)
13405       ,p_reference_num_4          => l_array_reference_num_4(Idx)
13406       ,p_reference_char_1         => l_array_reference_char_1(Idx)
13407       ,p_reference_char_2         => l_array_reference_char_2(Idx)
13408       ,p_reference_char_3         => l_array_reference_char_3(Idx)
13409       ,p_reference_char_4         => l_array_reference_char_4(Idx)
13410       ,p_reference_date_1         => l_array_reference_date_1(Idx)
13411       ,p_reference_date_2         => l_array_reference_date_2(Idx)
13412       ,p_reference_date_3         => l_array_reference_date_3(Idx)
13413       ,p_reference_date_4         => l_array_reference_date_4(Idx)
13414       ,p_event_created_by         => l_array_event_created_by(Idx)
13415       ,p_budgetary_control_flag   => l_array_budgetary_control_flag(Idx));
13416        --
13417 END IF;
13418 
13419 
13420 
13421 --
13422 xla_ae_lines_pkg.SetExtractLine(p_extract_line => l_array_extract_line_num(Idx));
13423 
13424 l_acct_reversal_source := SUBSTR(NULL, 1,30);
13425 
13426 IF l_continue_with_lines THEN
13427    IF NVL(l_acct_reversal_source, 'N') NOT IN ('N','Y','B') THEN
13428       xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
13429 
13430       xla_accounting_err_pkg.build_message
13431          (p_appli_s_name            => 'XLA'
13432          ,p_msg_name                => 'XLA_AP_INVALID_REVERSAL_OPTION'
13433          ,p_token_1                 => 'LINE_NUMBER'
13434          ,p_value_1                 => l_array_extract_line_num(Idx)
13435          ,p_token_2                 => 'PRODUCT_NAME'
13436          ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
13437          ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
13438          ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
13439          ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
13440 
13441    ELSIF NVL(l_acct_reversal_source, 'N') IN ('Y','B') THEN
13442       --
13443       -- following sets the accounting attributes needed to reverse
13444       -- accounting for a distributeion
13445       --
13446 
13447       --
13448       -- 5217187
13449       --
13450       l_rec_rev_acct_attrs.array_acct_attr_code(1):= 'GL_DATE';
13451       l_rec_rev_acct_attrs.array_date_value(1) := XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(
13452                                        g_array_event(l_event_id).array_value_num('header_index'));
13453       --
13454       --
13455 
13456       -- No reversal code generated
13460          ,p_rec_acct_attrs       => l_rec_rev_acct_attrs
13457 
13458       xla_ae_lines_pkg.SetAcctReversalAttrs
13459          (p_event_id             => l_event_id
13461          ,p_calculate_acctd_flag => l_calculate_acctd_flag
13462          ,p_calculate_g_l_flag   => l_calculate_g_l_flag);
13463    END IF;
13464 
13465    IF NVL(l_acct_reversal_source, 'N') IN ('N','B') THEN
13466        l_actual_flag := NULL;  l_actual_gain_loss_ref := '#####';
13467 
13468 --
13469 AcctLineType_16 (
13470  p_application_id  => p_application_id
13471  ,p_event_id     => l_event_id
13472  ,p_calculate_acctd_flag => l_calculate_acctd_flag
13473  ,p_calculate_g_l_flag => l_calculate_g_l_flag
13474  ,p_actual_flag => l_actual_flag
13475  ,p_balance_type_code => l_balance_type_code
13476  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
13477  
13478  , p_source_1 => l_array_source_1(Idx)
13479  , p_source_5 => l_array_source_5(Idx)
13480  , p_source_6 => l_array_source_6(Idx)
13481  , p_source_8 => l_array_source_8(Idx)
13482  , p_source_9 => g_array_event(l_event_id).array_value_char('source_9')
13483  , p_source_10 => l_array_source_10(Idx)
13484  , p_source_11 => l_array_source_11(Idx)
13485  );
13486 If(l_balance_type_code = 'A') THEN
13487   l_actual_gain_loss_ref := l_gain_or_loss_ref;
13488 END IF;
13489 
13490 --
13491 
13492 
13493 --
13494 AcctLineType_17 (
13495  p_application_id  => p_application_id
13496  ,p_event_id     => l_event_id
13497  ,p_calculate_acctd_flag => l_calculate_acctd_flag
13498  ,p_calculate_g_l_flag => l_calculate_g_l_flag
13499  ,p_actual_flag => l_actual_flag
13500  ,p_balance_type_code => l_balance_type_code
13501  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
13502  
13503  , p_source_1 => l_array_source_1(Idx)
13504  , p_source_5 => l_array_source_5(Idx)
13505  , p_source_8 => l_array_source_8(Idx)
13506  , p_source_9 => g_array_event(l_event_id).array_value_char('source_9')
13507  , p_source_10 => l_array_source_10(Idx)
13508  , p_source_11 => l_array_source_11(Idx)
13509  , p_source_12 => l_array_source_12(Idx)
13510  );
13511 If(l_balance_type_code = 'A') THEN
13512   l_actual_gain_loss_ref := l_gain_or_loss_ref;
13513 END IF;
13514 
13515 --
13516 
13517       -- only execute it if calculate g/l flag is yes, and primary or secondary ledger
13518       -- or secondary ledger that has different currency with primary
13519       -- or alc that is calculated by sla
13520       IF (((l_calculate_g_l_flag = 'Y' AND XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_category_code <> 'ALC') or
13521             (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_category_code in ('ALC', 'SECONDARY') AND XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.calculate_amts_flag='Y'))
13522 
13523 --      IF((l_calculate_g_l_flag='Y' or XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id <>
13524 --                    XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id)
13525           AND (l_actual_flag = 'A')) THEN
13526         XLA_AE_LINES_PKG.CreateGainOrLossLines(
13527           p_event_id         => xla_ae_journal_entry_pkg.g_cache_event.event_id
13528          ,p_application_id   => p_application_id
13529          ,p_amb_context_code => 'DEFAULT'
13530          ,p_entity_code      => xla_ae_journal_entry_pkg.g_cache_event.entity_code
13531          ,p_event_class_code => C_EVENT_CLASS_CODE
13532          ,p_event_type_code  => C_EVENT_TYPE_CODE
13533          
13534          ,p_gain_ccid        => -1
13535          ,p_loss_ccid        => -1
13536 
13537          ,p_actual_flag      => l_actual_flag
13538          ,p_enc_flag         => null
13539          ,p_actual_g_l_ref   => l_actual_gain_loss_ref
13540          ,p_enc_g_l_ref      => null
13541          );
13542       END IF;
13543    END IF;
13544 END IF;
13545 
13546    ELSE
13547       --
13548       -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
13549       --
13550       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
13551          trace
13552             (p_msg      => 'Trancaction revesal option is Y'
13553             ,p_level    => C_LEVEL_STATEMENT
13554             ,p_module   => l_log_module);
13555       END IF;
13556    END IF;
13557 
13558 END LOOP;
13559 l_result := XLA_AE_LINES_PKG.InsertLines ;
13560 end loop;
13561 close line_cur;
13562 
13563 
13564 --
13565 -- insert headers into xla_ae_headers_gt table
13566 --
13567 l_result := XLA_AE_HEADER_PKG.InsertHeaders ;
13568 
13569 -- insert into errors table here.
13570 
13571 END LOOP;
13572 
13573 --
13574 -- 4865292
13575 --
13576 -- Compare g_hdr_extract_count with event count in
13577 -- CreateHeadersAndLines.
13578 --
13579 g_hdr_extract_count := g_hdr_extract_count + header_cur%ROWCOUNT;
13580 
13581 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
13582    trace (p_msg     => '# rows extracted from header extract objects '
13583                     || ' (running total): '
13584                     || g_hdr_extract_count
13585          ,p_level   => C_LEVEL_STATEMENT
13586          ,p_module  => l_log_module);
13587 END IF;
13588 
13589 CLOSE header_cur;
13590 --
13591 
13592 --
13593 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
13594    trace
13595       (p_msg      => 'END of EventClass_22'
13596       ,p_level    => C_LEVEL_PROCEDURE
13597       ,p_module   => l_log_module);
13598 END IF;
13599 --
13600 RETURN l_result;
13601 EXCEPTION
13602 WHEN xla_exceptions_pkg.application_exception THEN
13603    
13604 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
13605 
13606    
13607 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
13608 
13609    RAISE;
13610 WHEN OTHERS THEN
13611    xla_exceptions_pkg.raise_message
13615 
13612       (p_location => 'XLA_08407_AAD_S_000013_BC_PKG.EventClass_22');
13613 END EventClass_22;
13614 --
13616 --
13617 --+============================================+
13618 --|                                            |
13619 --|  PRIVATE FUNCTION                          |
13620 --|                                            |
13621 --+============================================+
13622 --
13623 FUNCTION CreateHeadersAndLines
13624        (p_application_id         IN NUMBER
13625        ,p_base_ledger_id         IN NUMBER
13626        ,p_target_ledger_id       IN NUMBER
13627        ,p_pad_start_date         IN DATE
13628        ,p_pad_end_date           IN DATE
13629        ,p_primary_ledger_id      IN NUMBER)
13630 RETURN BOOLEAN IS
13631 l_created                   BOOLEAN:=FALSE;
13632 l_event_id                  NUMBER;
13633 l_event_date                DATE;
13634 l_language                  VARCHAR2(30);
13635 l_currency_code             VARCHAR2(30);
13636 l_sla_ledger_id             NUMBER;
13637 l_log_module                VARCHAR2(240);
13638 
13639 BEGIN
13640 --
13641 IF g_log_enabled THEN
13642    l_log_module := C_DEFAULT_MODULE||'.CreateHeadersAndLines';
13643 END IF;
13644 --
13645 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
13646    trace
13647       (p_msg      => 'BEGIN of CreateHeadersAndLines'
13648       ,p_level    => C_LEVEL_PROCEDURE
13649       ,p_module   => l_log_module);
13650 END IF;
13651 
13652 l_language         := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
13653 l_currency_code    := xla_ae_journal_entry_pkg.g_cache_ledgers_info.currency_code;
13654 l_sla_ledger_id    := xla_ae_journal_entry_pkg.g_cache_ledgers_info.sla_ledger_id;
13655 
13656 --
13657 -- initialize array of lines with NULL
13658 --
13659 xla_ae_lines_pkg.SetNullLine;
13660 
13661 --
13662 -- initialize header extract count -- Bug 4865292
13663 --
13664 g_hdr_extract_count:= 0;
13665 
13666 
13667 l_created := EventClass_18(
13668    p_application_id         => p_application_id
13669  , p_base_ledger_id         => p_base_ledger_id
13670  , p_target_ledger_id       => p_target_ledger_id
13671  , p_language               => l_language
13672  , p_currency_code          => l_currency_code
13673  , p_sla_ledger_id          => l_sla_ledger_id
13674  , p_pad_start_date         => p_pad_start_date
13675  , p_pad_end_date           => p_pad_end_date
13676  , p_primary_ledger_id      => p_primary_ledger_id
13677 );
13678 
13679 
13680 
13681      IF ( g_diagnostics_mode ='Y' ) THEN
13682 
13683          IF (C_LEVEL_STATEMENT >= g_log_level) THEN
13684           trace
13685               (p_msg      => 'CALL Transaction Objects Diagnostics'
13686               ,p_level    => C_LEVEL_STATEMENT
13687               ,p_module   => l_log_module);
13688 
13689          END IF;
13690 
13691          insert_sources_18(
13692                           p_target_ledger_id => p_target_ledger_id
13693                         , p_language         => l_language
13694                         , p_sla_ledger_id    => l_sla_ledger_id
13695                         , p_pad_start_date   => p_pad_start_date
13696                         , p_pad_end_date     => p_pad_end_date
13697                           );
13698 
13699      END IF;
13700 
13701 l_created := EventClass_19(
13702    p_application_id         => p_application_id
13703  , p_base_ledger_id         => p_base_ledger_id
13704  , p_target_ledger_id       => p_target_ledger_id
13705  , p_language               => l_language
13706  , p_currency_code          => l_currency_code
13707  , p_sla_ledger_id          => l_sla_ledger_id
13708  , p_pad_start_date         => p_pad_start_date
13709  , p_pad_end_date           => p_pad_end_date
13710  , p_primary_ledger_id      => p_primary_ledger_id
13711 );
13712 
13713 
13714 
13715      IF ( g_diagnostics_mode ='Y' ) THEN
13716 
13717          IF (C_LEVEL_STATEMENT >= g_log_level) THEN
13718           trace
13719               (p_msg      => 'CALL Transaction Objects Diagnostics'
13720               ,p_level    => C_LEVEL_STATEMENT
13721               ,p_module   => l_log_module);
13722 
13723          END IF;
13724 
13725          insert_sources_19(
13726                           p_target_ledger_id => p_target_ledger_id
13727                         , p_language         => l_language
13728                         , p_sla_ledger_id    => l_sla_ledger_id
13729                         , p_pad_start_date   => p_pad_start_date
13730                         , p_pad_end_date     => p_pad_end_date
13731                           );
13732 
13733      END IF;
13734 
13735 l_created := EventClass_20(
13736    p_application_id         => p_application_id
13737  , p_base_ledger_id         => p_base_ledger_id
13738  , p_target_ledger_id       => p_target_ledger_id
13739  , p_language               => l_language
13740  , p_currency_code          => l_currency_code
13741  , p_sla_ledger_id          => l_sla_ledger_id
13742  , p_pad_start_date         => p_pad_start_date
13743  , p_pad_end_date           => p_pad_end_date
13744  , p_primary_ledger_id      => p_primary_ledger_id
13745 );
13746 
13747 
13748 
13749      IF ( g_diagnostics_mode ='Y' ) THEN
13750 
13751          IF (C_LEVEL_STATEMENT >= g_log_level) THEN
13752           trace
13753               (p_msg      => 'CALL Transaction Objects Diagnostics'
13754               ,p_level    => C_LEVEL_STATEMENT
13755               ,p_module   => l_log_module);
13756 
13757          END IF;
13758 
13759          insert_sources_20(
13760                           p_target_ledger_id => p_target_ledger_id
13761                         , p_language         => l_language
13765                           );
13762                         , p_sla_ledger_id    => l_sla_ledger_id
13763                         , p_pad_start_date   => p_pad_start_date
13764                         , p_pad_end_date     => p_pad_end_date
13766 
13767      END IF;
13768 
13769 l_created := EventClass_21(
13770    p_application_id         => p_application_id
13771  , p_base_ledger_id         => p_base_ledger_id
13772  , p_target_ledger_id       => p_target_ledger_id
13773  , p_language               => l_language
13774  , p_currency_code          => l_currency_code
13775  , p_sla_ledger_id          => l_sla_ledger_id
13776  , p_pad_start_date         => p_pad_start_date
13777  , p_pad_end_date           => p_pad_end_date
13778  , p_primary_ledger_id      => p_primary_ledger_id
13779 );
13780 
13781 
13782 
13783      IF ( g_diagnostics_mode ='Y' ) THEN
13784 
13785          IF (C_LEVEL_STATEMENT >= g_log_level) THEN
13786           trace
13787               (p_msg      => 'CALL Transaction Objects Diagnostics'
13788               ,p_level    => C_LEVEL_STATEMENT
13789               ,p_module   => l_log_module);
13790 
13791          END IF;
13792 
13793          insert_sources_21(
13794                           p_target_ledger_id => p_target_ledger_id
13795                         , p_language         => l_language
13796                         , p_sla_ledger_id    => l_sla_ledger_id
13797                         , p_pad_start_date   => p_pad_start_date
13798                         , p_pad_end_date     => p_pad_end_date
13799                           );
13800 
13801      END IF;
13802 
13803 l_created := EventClass_22(
13804    p_application_id         => p_application_id
13805  , p_base_ledger_id         => p_base_ledger_id
13806  , p_target_ledger_id       => p_target_ledger_id
13807  , p_language               => l_language
13808  , p_currency_code          => l_currency_code
13809  , p_sla_ledger_id          => l_sla_ledger_id
13810  , p_pad_start_date         => p_pad_start_date
13811  , p_pad_end_date           => p_pad_end_date
13812  , p_primary_ledger_id      => p_primary_ledger_id
13813 );
13814 
13815 
13816 
13817      IF ( g_diagnostics_mode ='Y' ) THEN
13818 
13819          IF (C_LEVEL_STATEMENT >= g_log_level) THEN
13820           trace
13821               (p_msg      => 'CALL Transaction Objects Diagnostics'
13822               ,p_level    => C_LEVEL_STATEMENT
13823               ,p_module   => l_log_module);
13824 
13825          END IF;
13826 
13827          insert_sources_22(
13828                           p_target_ledger_id => p_target_ledger_id
13829                         , p_language         => l_language
13830                         , p_sla_ledger_id    => l_sla_ledger_id
13831                         , p_pad_start_date   => p_pad_start_date
13832                         , p_pad_end_date     => p_pad_end_date
13833                           );
13834 
13835      END IF;
13836 
13837 
13838  --
13839  -- Bug 4865292
13840  -- When the number of events and that of header extract do not match,
13841  -- set the no header extract flag to indicate there are some issues
13842  -- in header extract.
13843  --
13844  -- Event count context is set in xla_accounting_pkg.unit_processor.
13845  -- Build_Message for this error is called in xla_accounting_pkg.post_accounting
13846  -- to report it as a general error.
13847  --
13848  IF  xla_context_pkg.get_event_count_context <> g_hdr_extract_count
13849  AND xla_context_pkg.get_event_nohdr_context <> 'Y' THEN
13850 
13851      IF (C_LEVEL_STATEMENT >= g_log_level) THEN
13852         trace
13853           (p_msg      => '# of extracted headers and events does not match'
13854           ,p_level    => C_LEVEL_STATEMENT
13855           ,p_module   => l_log_module);
13856 
13857         trace
13858           (p_msg      => '# of extracted headers: '
13859                          ||g_hdr_extract_count
13860           ,p_level    => C_LEVEL_STATEMENT
13861           ,p_module   => l_log_module);
13862 
13863         trace
13864           (p_msg      => '# of events in xla_events_gt: '
13865                          ||xla_context_pkg.get_event_count_context
13866           ,p_level    => C_LEVEL_STATEMENT
13867           ,p_module   => l_log_module);
13868 
13869         trace
13870           (p_msg      => 'Event No Header Extract Context: '
13871                          ||xla_context_pkg.get_event_nohdr_context
13872           ,p_level    => C_LEVEL_STATEMENT
13873           ,p_module   => l_log_module);
13874 
13875      END IF;
13876 
13877 
13878      xla_context_pkg.set_event_nohdr_context
13879        (p_nohdr_extract_flag => 'Y'
13880        ,p_client_id => sys_context('USERENV','CLIENT_IDENTIFIER'));
13881 
13882      IF (C_LEVEL_STATEMENT >= g_log_level) THEN
13883         trace
13884           (p_msg      => 'No Header Extract Flag is set to Y'
13885           ,p_level    => C_LEVEL_STATEMENT
13886           ,p_module   => l_log_module);
13887      END IF;
13888 
13889  END IF;
13890 
13891 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
13892    trace
13893       (p_msg      => 'END of CreateHeadersAndLines'
13894       ,p_level    => C_LEVEL_PROCEDURE
13895       ,p_module   => l_log_module);
13896 END IF;
13897 
13898 RETURN l_created;
13899 EXCEPTION
13900 WHEN xla_exceptions_pkg.application_exception THEN
13901    RAISE;
13902 WHEN OTHERS THEN
13903    xla_exceptions_pkg.raise_message
13904       (p_location => 'XLA_08407_AAD_S_000013_BC_PKG.CreateHeadersAndLines');
13905 END CreateHeadersAndLines;
13906 --
13907 --
13908 
13909 --
13910 --+============================================+
13911 --|                                            |
13912 --|  PUBLIC FUNCTION                           |
13913 --|                                            |
13914 --+============================================+
13915 --
13916 FUNCTION CreateJournalEntries
13917        (p_application_id         IN NUMBER
13918        ,p_base_ledger_id         IN NUMBER
13919        ,p_pad_start_date         IN DATE
13920        ,p_pad_end_date           IN DATE
13921        ,p_primary_ledger_id      IN NUMBER)
13922 RETURN NUMBER IS
13923 l_log_module                   VARCHAR2(240);
13924 l_array_ledgers                xla_accounting_cache_pkg.t_array_ledger_id;
13925 l_temp_result                  BOOLEAN;
13926 l_result                       NUMBER;
13927 BEGIN
13928 --
13929 IF g_log_enabled THEN
13930    l_log_module := C_DEFAULT_MODULE||'.CreateJournalEntries';
13931 END IF;
13932 --
13933 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
13934    trace
13935       (p_msg      => 'BEGIN of CreateJournalEntries'||
13936                      ' - p_base_ledger_id = '||TO_CHAR(p_base_ledger_id)
13937       ,p_level    => C_LEVEL_PROCEDURE
13938       ,p_module   => l_log_module);
13939 
13940 END IF;
13941 
13942 --
13943 g_diagnostics_mode:= xla_accounting_engine_pkg.g_diagnostics_mode;
13944 
13945 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
13946    trace
13947       (p_msg      => 'g_diagnostics_mode = '||g_diagnostics_mode
13948       ,p_level    => C_LEVEL_STATEMENT
13949       ,p_module   => l_log_module);
13950 END IF;
13951 --
13952 xla_ae_journal_entry_pkg.SetProductAcctDefinition
13953    (p_product_rule_code      => 'CC_ENC_COMMON'
13954    ,p_product_rule_type_code => 'S'
13955    ,p_product_rule_version   => ''
13956    ,p_product_rule_name      => 'CC Encumbrance Common'
13957    ,p_amb_context_code       => 'DEFAULT'
13958    );
13959 
13960 l_array_ledgers :=
13961    xla_ae_journal_entry_pkg.GetAlternateCurrencyLedger
13962       (p_base_ledger_id  => p_base_ledger_id);
13963 
13964 FOR Idx IN 1 .. l_array_ledgers.COUNT LOOP
13965    l_temp_result :=
13966       XLA_AE_JOURNAL_ENTRY_PKG.GetLedgersInfo
13967          (p_application_id           => p_application_id
13968          ,p_base_ledger_id           => p_base_ledger_id
13969          ,p_target_ledger_id         => l_array_ledgers(Idx)
13970          ,p_primary_ledger_id        => p_primary_ledger_id
13971          ,p_pad_start_date           => p_pad_start_date
13972          ,p_pad_end_date             => p_pad_end_date);
13973 
13974    l_temp_result :=
13975       l_temp_result AND
13976       CreateHeadersAndLines
13977          (p_application_id             => p_application_id
13978          ,p_base_ledger_id             => p_base_ledger_id
13979          ,p_target_ledger_id           => l_array_ledgers(Idx)
13980          ,p_pad_start_date             => p_pad_start_date
13981          ,p_pad_end_date               => p_pad_end_date
13982          ,p_primary_ledger_id          => p_primary_ledger_id
13983          );
13984 END LOOP;
13985 
13986 
13987 IF (g_diagnostics_mode = 'Y' AND
13988     C_LEVEL_UNEXPECTED >= g_log_level AND
13989     xla_environment_pkg.g_Req_Id IS NOT NULL ) THEN
13990 
13991    xla_accounting_dump_pkg.acctg_event_extract_log(
13992     p_application_id  => p_application_id
13993     ,p_request_id     => xla_environment_pkg.g_Req_Id
13994    );
13995 
13996 END IF;
13997 
13998 CASE l_temp_result
13999   WHEN TRUE THEN l_result := 0;
14000   ELSE l_result := 2;
14001 END CASE;
14002 
14003 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
14004    trace
14005       (p_msg      => 'return value. = '||TO_CHAR(l_result)
14006       ,p_level    => C_LEVEL_PROCEDURE
14007       ,p_module   => l_log_module);
14008    trace
14009       (p_msg      => 'END of CreateJournalEntries '
14010       ,p_level    => C_LEVEL_PROCEDURE
14011       ,p_module   => l_log_module);
14012 END IF;
14013 
14014 RETURN l_result;
14015 EXCEPTION
14016 WHEN xla_exceptions_pkg.application_exception THEN
14017    IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
14018    trace
14019       (p_msg      => 'ERROR. = '||sqlerrm
14020       ,p_level    => C_LEVEL_PROCEDURE
14021       ,p_module   => l_log_module);
14022    END IF;
14023    RAISE;
14024 WHEN OTHERS THEN
14025    IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
14026    trace
14027       (p_msg      => 'ERROR. = '||sqlerrm
14028       ,p_level    => C_LEVEL_PROCEDURE
14029       ,p_module   => l_log_module);
14030    END IF;
14031    xla_exceptions_pkg.raise_message
14032       (p_location => 'XLA_08407_AAD_S_000013_BC_PKG.CreateJournalEntries');
14033 END CreateJournalEntries;
14034 --
14035 --=============================================================================
14036 --
14037 --
14038 --
14039 --
14040 --
14041 --
14042 --
14043 --
14044 --
14045 --
14046 --
14047 --
14048 --
14049 --
14050 --
14051 --
14052 --
14053 --
14054 --
14055 --
14056 --
14057 --
14058 --=============================================================================
14059 --=============================================================================
14060 --          *********** Initialization routine **********
14061 --=============================================================================
14062 
14063 BEGIN
14064    g_log_level      := FND_LOG.G_CURRENT_RUNTIME_LEVEL;
14065    g_log_enabled    := fnd_log.test
14066                           (log_level  => g_log_level
14067                           ,module     => C_DEFAULT_MODULE);
14068 
14069    IF NOT g_log_enabled  THEN
14070       g_log_level := C_LEVEL_LOG_DISABLED;
14071    END IF;
14072 --
14073 END XLA_08407_AAD_S_000013_BC_PKG;
14074 --